在Apache中,我通过在.htaccess文件中添加以下内容来启用输出压缩:
# compress text, html, javascript, css, xml:
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
# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE
</Files>
所以我用内容编码:gzip提供所有内容,但当我用Yslow测试我的网页时,我会收到:
Grade D on Compress components with gzip
There are 3 plain text components that should be sent compressed
* http://mysite.com/javascript/youTubeEmbed/youTubeEmbed-jquery-1.0.css
* http://mysite.com/javascript/jquery.swfobject.1-1-1.min.js
* http://mysite.com/javascript/youTubeEmbed/youTubeEmbed-jquery-1.0.js
问题出在哪里?它们不应该自动压缩吗??
感谢
Luca
您记得在重新加载页面并运行Yslow之前清除缓存吗?
我也遇到了同样的问题,就这样解决了。这是我的代码:
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
在我的案例中,我只需将此行添加到.htaccess文件中就解决了完全相同的问题:AddOutputFilterByType DEFLATE text/javascript
也许服务器没有将javascript作为application/javascript,而是将其作为text/javascript。希望能有所帮助。
在我的情况下,我不得不删除反向代理服务器(nginx)-当然,你也可以使用nginx.conf文件(可能位于/etc/nginx中,也可以使用/etc/nginx/conf.d目录中自己的.conf文件)配置压缩-但nginx引起了一些其他问题。使用Plesk从服务器中删除nginx后,请查看以下提示:http://forum.parallels.com/showthread.php?t=260563长话短说:注意这些文件是真的由Apache提供的,还是由nginx之类的东西处理的。B.t.w.一种快速测试工具:http://www.gidnetwork.com/tools/gzip-test.php