如何通过Apache2发送压缩(放气)SVG? [英] How to send compressed (deflated) SVG via Apache2?
问题描述
我在网站的 .htaccess
文件中指定了以下属性:
I have specified the following attributes in my site's .htaccess
file:
AddOutputFilterByType DEFLATE image/svg+xml
DeflateCompressionLevel 9
Header append Vary Accept-Encoding
但是,我的 SVG 资源并未以压缩形式发送:
However, my SVG asset is not being sent in compressed form:
$ curl https://example.org/assets/svg/asset.svg --silent -H "Accept-Encoding: gzip,deflate" --write-out "${size_download}\n" --output /dev/null
152655
$ curl https://example.org/assets/svg/asset.svg --silent --write-out "%{size_download}\n" --output /dev/null
152655
我确认此资产 (asset.svg
) 是使用 Chrome 以 MIME 类型 image/svg+xml
发送的,但使用 Web Developer 工具,此特定文件在发送到客户端时没有被压缩.
I verified that this asset (asset.svg
) is being sent with MIME type image/svg+xml
using Chrome, but using the Web Developer tools, this specific file is not being compressed when sent to the client.
将其他 MIME 类型添加到 .htaccess
文件是成功的(例如,添加 text/html
会压缩 HTML 资产).
Adding other MIME types to the .htaccess
file is successful (e.g., adding text/html
compresses the HTML assets).
这似乎特定于 SVG 数据的处理方式.我还可以尝试或排除哪些问题来使 SVG 压缩正常工作?
This seems specific to how SVG data are handled. What else can I try or troubleshoot to get SVG compression working?
推荐答案
如果 Apache 不知道文件的 mime 类型(这里是 image/svg+xml),则需要具体告诉它(大多数 Apache 不需要):
If Apache doesn't know the mime type of the file (here image/svg+xml), you need to tell it specifically (not needed in most Apaches):
AddType image/svg+xml svg svgz
现在当 Apache 知道文件类型时,只需添加以下内容即可压缩它:
Now when Apache knows about the filetype, just add this to deflate it:
AddOutputFilterByType DEFLATE image/svg+xml
有关更多信息,请参阅 https://httpd.apache.org/docs/2.4/mod/mod_deflate.html
For more information see https://httpd.apache.org/docs/2.4/mod/mod_deflate.html
这篇关于如何通过Apache2发送压缩(放气)SVG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!