MIME Type

From Svg wiki

Internet media types (commonly known as "MIME types") are the primary method to indicate the type of resources delivered via MIME-aware protocols such as HTTP and E-mail. User agents use media types to determine whether a specific format is supported and how the content should be processed. When SVG documents are not labeled as such they might not work as intended by the author, for example, a browser might render them as plain text or provide a save-as dialog instead of rendering the images.

The MIME Type for SVG documents is image/svg+xml (so PLUS xml, NOT MINUS xml, that's outdated), see SVG MIME type in the SVG 1.1 Recommendation. It is expected that the type will be officially registered in the IANA media type registry for image/* media types with the advancement of SVG Tiny 1.2 which includes the latest definition of the type. When that happened, it basically means that every up-to-date webserver handles SVG properly by default.

Test whether your SVG is served correctly (Content-Type: image/svg+xml) with Web-Sniffer.net If it's not you can do 2 things:

  • adjust the server settings (See below how to do that for some often used servers), or ask the server administrator to do so (send him the URL to this page). This way you fix it for every directory and everybody having an account on that server.
  • If there's no file named exactly ".htaccess" in the same directory as the SVG file, create it. Then add the following 2 lines to the file you found or created:
AddType image/svg+xml svg
AddType image/svg+xml svgz

Older versions of Internet Explorer (before version 6) do not behave properly in respect to SVG and MIME types. They treat SVG as SVG when, and only when, the URL ends in .svg, it doesn't care about MIME.

So, in order to have all browsers accept your content properly:

 1. set the MIME type on the server.
 2. make sure URLs end in .svg, maybe using a dummy parameter as in "http://mysvg.jsp?ielikes=.svg"

Contents

MIME Type Checker

You can ensure that you are serving the correct MIME or Content-Type (image/svg+xml) at Web-Sniffer.net.

Apache-Linux

To set the SVG MIME type for my apache server on debian linux, I had to edit the file /etc/apache/mime.types and add the line

image/svg+xml   svg svgz

Your mileage may vary.

There are also instructions at http://www.svgfaq.com/servergen.asp for setting the MIME type for IIS.

If your site is hosted and you don't have full admin access to the server, it is generally possible on a Unix box to set it yourself with an .htaccess file as described at the above URL. If however your server is hosted by an NT/2000 host, you may have to convince your host to set the MIME type.

Apache-Windows

as for Apache-Linux above, only in (Apache dir)/conf/mime.types


Jakarta Tomcat

Tomcat Version 4.1.29 has defined the MIME Type for SVG already. Older Versions need to add the following to (Tomcat dir)/conf/web.xml

<mime-mapping>
   <extension>svg</extension>
   <mime-type>image/svg+xml</mime-type>
</mime-mapping>

<mime-mapping>
   <extension>svgz</extension>
   <mime-type>image/svg+xml</mime-type>
</mime-mapping>

If you only want this setting to apply to a specific app, then put it in that app's own web.xml instead.

-- DannyAyers

The IE trick doesn't work with the iframe tag. We had to use the object tag with IE conditional comment to render SVG for all browsers :

<!--[[if gte IE 5]]>
  <object type="image/svg+xml" data="generateSVG.jsp" NAME="owMain" width="580" height="300" ></object>
<![[endif]]-->
<![[if lt IE 5]]>
 <iframe src="generateSVG.jsp" width="580px" height="300px" frameborder="0" marginwidth="0"  marginheight="0" >
    <embed src="generateSVG.jsp" width="580px" height="300px" />
  </iframe>
<![[endif]]>

See Also

* Server Configuration
* http://esw.w3.org/topic/MarkupValidator/Feedback
* Server configuration section of Jonathan Watt's SVG authoring guidelines - read the rest of this page as well!