使用.htaccess将SVG用作Apache上的映像

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:

自从使用Dojo Toolkit创建图表和动画以来,我一直是SVG的忠实拥护者 。 SVG已经存在了很长时间,甚至现在都支持IE,而且它非常灵活。 在创建该网站的重新设计时,我在IMG标签中使用了SVG,并且在本地效果很好。 但是,当我推送到实时服务器时,该图像显示为损坏,并且在控制台中看到以下通知:


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:

这当然是出乎意料的。 显然,本地服务器和生产服务器之间存在差异,因此,经过一些研究,我发现以下.htaccess更新将解决此问题:


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!

SVG作为XML的本质,实际上对我没有用-我想在视觉上使用它。 请妥善保存此代码段,以防您也遇到此问题!

翻译自: https://davidwalsh.name/serve-svg-image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值