gpt4 book ai didi

.htaccess - 如何通过 Apache2 发送压缩(放气)的 SVG?

转载 作者:行者123 更新时间:2023-12-03 01:45:28 25 4
gpt4 key购买 nike

我已在网站的 .htaccess 文件中指定了以下属性:

AddOutputFilterByType DEFLATE image/svg+xml
DeflateCompressionLevel 9
Header append Vary Accept-Encoding

但是,我的 SVG 资源并未以压缩形式发送:

$ 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 开发人员工具,此特定文件在发送到客户端时未经过压缩。

将其他 MIME 类型添加到 .htaccess 文件成功(例如,添加 text/html 压缩 HTML 资源)。

这似乎特定于 SVG 数据的处理方式。我还可以尝试什么或排除故障以使 SVG 压缩正常工作?

最佳答案

如果 Apache 不知道文件的 mime 类型(此处为 image/svg+xml),则需要具体告知(大多数 Apache 中不需要):

AddType image/svg+xml svg svgz

现在,当 Apache 知道文件类型时,只需添加以下内容即可缩小它:

AddOutputFilterByType DEFLATE image/svg+xml

有关更多信息,请参阅 https://httpd.apache.org/docs/2.4/mod/mod_deflate.html

关于.htaccess - 如何通过 Apache2 发送压缩(放气)的 SVG?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21356811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com