Issue with MIME types and serving svg: Resource in

2019-08-12 05:56发布

I'm targeting some SVG images with CSS to use as backgrounds on a few elements and having some strange issues. When going directly to the image it works fine, but when using in CSS I get the following error:

Resource interpreted as Image but transferred with MIME type text/xml

I've added an .htaccess file to the directory that serves the images with the following code, but it didn't help:

AddType image/svg+xml svg

Suggestions?

2条回答
贪生不怕死
2楼-- · 2019-08-12 06:19

The probable explanation is that previously the HTTP headers specified a wrong content type, and now that you have fixed it, some software uses cached information. (Not uncommon when using XML files.) The simple way to check things out is to create a copy of the .svg file and refer to it in CSS using the new name.

When I test the URL you gave in a simple background rule, the image shows without problems on Firefox, IE, Chrome, Safari (tested on Win 7). But when I test this so that Content-Type: text/xml is sent by a server, all the browsers simply don’t show a background image; no error message is shown. So I suppose you tested with some special browser or with special settings.

查看更多
欢心
3楼-- · 2019-08-12 06:22

Updating .htaccess did not work for me. I added following line in /etc/mime.types and restarted apache server, cleared cache and it worked.

image/svg+xml                   svg
查看更多
登录 后发表回答