我的 .htaccess
文件中有这个:
# gzip compression
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript application/json
</ifmodule>
这可确保给定的内容类型经过 gzip 压缩。
现场演示: http://ecmazing.com/js/index.js (在浏览器的开发工具中打开“Net”面板,然后查看响应 header )
但是我的 Markdown 文件没有被 gzip 压缩。
现场演示: http://ecmazing.com/data.md
如您所见,文件的内容类型为 text/plain
,它位于我的 .htaccess
文件的内容类型列表中。那么,为什么不应用GZIP呢?
最佳答案
我猜你的 Markdown 文件没有通过 AddType
指令主动分配内容类型 text/plain
- 因此服务器可能会将该内容类型发送为默认值,但 AddOutputFilterByType
不会自动将这些文件识别为该内容类型。
http://httpd.apache.org/docs/2.2/en/mod/core.html#addoutputfilterbytype证实了这一点,并说道:
“Enabling filters with AddOutputFilterByType may fail partially or completely in some cases. For example, no filters are applied if the MIME-type could not be determined and falls back to the DefaultType setting, even if the DefaultType is the same.”
因此,请使用 AddOutputFilter deflate md
,或者尝试使用 AddType text/plain md
将 .md
与内容类型显式关联。
关于apache - 为什么我的 Markdown 文件没有被压缩?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15499041/