Serve SVG as an Image on Apache with .htaccess
I've been a massive fan of SVG since my days creating charts and animations with the Dojo Toolkit. SVG has been around forever, it even has IE support now, and it's ultra-flexible. When creating this site's redesign, I used SVG within an IMG tag and it work great locally. When I pushed to the live server, however, the image displayed as broken and I saw the following notice in the console:
Resource interpreted as Image but transferred with MIME type text/xml: "https://davidwalsh.name/logo.svg".
That was certainly unexpected. Obviously there was a difference in my local server and my production server, so after a bit of research, I found that the following .htaccess update would resolve the issue:
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
Serving SVG as XML, what it essentially is, really isn't of use to me -- I want to use it in its visual glory. Keep this snippet handy in case you also run into this issue!
The <canvas>
element has been a revelation for the visual experts among our ranks. Canvas provides the means for incredible and efficient animations with the added bonus of no Flash; these developers can flash their awesome JavaScript skills instead. Here are nine unbelievable canvas demos that...
Your early CSS books were instrumental in pushing my love for front end technologies. What was it about CSS that you fell in love with and drove you to write about it?
At first blush, it was the simplicity of it as compared to the table-and-spacer...
One of the sweet effects made easy by JavaScript frameworks like MooTools and jQuery is animation. I ran across this great jQuery tutorial that walks you through animating a background image of a page. Here's a quick MooTools code snippet that...
One of the most popular code snippets of posted on my blog has been the scrolling "Go To Top" link snippet. The premise of the snippet is simple: once the user scrolls an element (usually the BODY element) past a given threshold, a "Go...
Nice, I always missed that one. But isn’t it better to user dots before the file endings? In the original documentation for AddType the example says so.
With which MIME type will it be transferred after adding this configuration?
image/svg+xml