

Ask HN:Whats the problem with SVG? - lousy_sysadmin

I've been playing around with Inkscape for a while now to create vector image as its one of the easiest solution for Retina-esque site. However I'm having a hard time finding image hosting that support SVG.<p>My question is, why is it so hard for image hosting service to support native SVG, instead of converting an image to other format. Would like to hear the limitations and challenges that comes with it.<p>http://imgur.userecho.com/topic/23630-svg-support/
======
jahewson
SVG implementations on browsers have historically been poor, though this is
certainly improving. You'll hit many bugs and unsupported features. IE < 9
doesn't support SVG at all, and Safari < 6 only does so in XHTML. SVG fonts
are sparsely supported. The alternative - rasterising SVG on the server - is a
heavyweight task, I've not found any libraries which can do this quickly.

The worst problem may be SVG itself - SVG 1.2 which dates from 2004 was
abandoned, and most browsers implement SVG 1.1 which is rather lacking in
features. This makes it hard if you're a designer to produce SVG documents
which a browser can actually render.

At a bare minimum any SVG hosting project would have to involve some sort of
SVG lint, to make sure that browser-incompatible SVG elements are not present,
implement workarounds for browser-specific bugs, and check that there are no
<script> tags etc. The sheer size and complexity of even SVG 1.1 makes it non-
trivial. One pragmatic approach to sanitize SVG may be to round-trip SVG ->
PDF -> SVG via cairosvg and pdftocairo, though it may burn some CPU.

~~~
mjn
_The alternative - rasterising SVG on the server - is a heavyweight task, I've
not found any libraries which can do this quickly._

Wikipedia does it using librsvg, fwiw: <https://live.gnome.org/LibRsvg>

~~~
jahewson
Cool!

------
nwh
I'd considered making one some time ago, but gave up when I realised that
somebody had already purchased <http://s.vg/>.

------
lmm
XML being XML, it's hard-to-impossible to host SVG without allowing people to
store arbitrary XML on your service, which sooner or later is going to be
abused.

~~~
emn13
That's true for almost any hosting service - it's usually quite easy to encode
other information in whatever wrapper is possible. Virtually all image formats
(for instance) allow arbitrary metadata, and usually of arbitrary size. And if
meta-data isn't allowed, a lossless format like PNG can easily be
reinterpreted as a simple byte-array (e.g. 8bpp greyscale image).

Of course, why would anyone bother? It's that hard to find hosters that will
host anything, so why do through the hassle to encruft your data with some
somewhat unwieldy wrapper?

The fact that it's XML is in some way a "protection" here since for no
particularly good reason some character codes cannot be represented by xml
(not even encoded), meaning you'll need ugly workarounds to store arbitrary
data.

------
mbq
_Arbitrary_ SVG is a security/privacy problem -- it may inject JS or exploit
quirks in rendering to manipulate site contents, import external images and
fonts, or simply be a render bomb. And it is hard to filter out those
problems.

~~~
nwh
You could just have a dedicated domain for it, then there's no risk of XSS.
It's doable, but it would be rather fragile.

The render bomb point is a little trickier, as you can use some detailed
filters to crash most browsers. Heck, even a single simple shape will crash
any version of iOS.

------
pre
It's not hard, probably the image hosts concerned merely didn't think to
include it.

You can upload svg files with the right content type to Amazon S3 without
trouble, is that not good enough?

------
youngtaff
My question is why do you want to host your SVG images elsewhere?

If you just want to shop them you could convert them to bitmap or host them on
GitHub

If you want to include them on your website, they're small and compress well
with gzip so why have the complexity of relying on a third party services

It you have too much traffic to be able to host them yourself then you should
look at something like a CDN e.g. Cloudfront, infront of S3

------
timrogers
I'm guessing you could maybe host it with Gists, using the raw link? Although
the content type headers might be an issue...

------
lsiebert
It's not hard. However, I'd note that IE didn't have built in support until
2011, and the first browser with native svg support was Konqueror in 2004,
whereas gif and jpeg have been around for a lot longer.

Isn't SVG just XML? I'd assume you could host it that way.

~~~
KorvinSzanto
It's XML based, really only uses a different schema.

~~~
tobyink
What schema does XML normally use?

~~~
Zash
XML has no default schema.

------
Turing_Machine
You might look at <http://openclipart.org/> to see how they're handling it.

------
wisty
IE6. XML viruses.

