我正在尽我所能地加速我的网站。我运行了谷歌的PageSpeed,得到了83/100。
页面要求压缩资源,如.js和.css文件。
“使用gzip或deflate压缩资源可以减少通过网络发送的字节数。”
好了,然后我用谷歌搜索并编辑了我的.htaccess:
<IfModule mod_deflate.c>
<FilesMatch "\.(css|js|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/png A604800
ExpiresByType image/gif A604800
ExpiresByType image/jpg A604800
ExpiresByType image/jpeg A604800
ExpiresByType text/javascript A604800
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
</IfModule>当我检查我的网站时:
标头:
Accept-Encoding gzip, deflate缓存:
Data Size 332
Device disk
Expires Thu Jan 01 1970 02:00:00和PHP在我的网站上:
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else
ob_start();
header('Vary: Accept');
header('Cache-Control: max-age=28800');你知道哪里出问题了吗?
发布于 2013-02-25 17:02:15
在上面的示例代码中,没有为html内容指定扩展名,例如.php
我通常通过mimetype而不是文件扩展名来管理gzip。
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
etc有关完整列表,请参阅https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess。
https://stackoverflow.com/questions/15030126
复制相似问题