压缩css在Firefox和Iphone safari中不起作用

时间:2015-06-04 05:35:34

标签: css .htaccess compression

我正在使用谷歌网页速度洞察,它建议我的css页面被压缩。所以我添加了这个htaccess

<filesMatch "\.(js|css)$">
Header set Content-Encoding x-deflate
# Header set Content-Encoding compress
# Header set Content-Encoding x-gzip
</filesMatch>

所以它正在压缩css并且在chrome中运行良好,但在firefox中当我访问http://fasttorrent.me/cdn/bootstrap.css css链接时它是空白的,我得到以下错误

The character encoding of the plain text document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the file needs to be declared in the transfer protocol or file needs to use a byte order mark as an encoding signature.

所以我在下面添加了代码

<filesMatch "\.css$">
FileETag None
<ifModule mod_headers.c>
Header set Content-type "text/css"
</ifModule>
</filesMatch>

但我仍然在firefox和iphone safari中遇到同样的错误。

编辑:我试图像下面那样设置字符集..还有错误

<filesMatch "\.(html|css|js)$">
AddDefaultCharset UTF-8
DefaultLanguage en-US
Header set Content-Encoding x-deflate
</filesMatch>

1 个答案:

答案 0 :(得分:0)

我之前遇到过类似的问题,看起来firefox不支持以下行,因为它们声明输出已压缩但实际上没有压缩它。 https://support.mozilla.org/en-US/questions/1063554

<filesMatch "\.(js|css)$">
Header set Content-Encoding x-deflate
# Header set Content-Encoding compress
# Header set Content-Encoding x-gzip
</filesMatch>

因此,根据此链接https://varvy.com/pagespeed/enable-compression.html我将其替换为以下内容,现在所有内容似乎都正常工作。

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript