2013-02-22 80 views
0

我想尽我所能加快我的网站。我跑Google的PageSpeed,得到83/100。谷歌PageSpeed压缩和.htaccess

页面表示压缩资源,如.js和.css文件。

“使用gzip或deflate压缩资源可以减少通过网络发送的字节数。”

欧凯,然后我用Google搜索和编辑我的.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'); 

任何想法发生了什么问题?

+0

不要在PHP中压缩输出,让Apache处理所有的输出。是否安装并启用了'mod_deflate'? – 2013-02-22 18:12:14

+0

删除了PHP输出。 mod_deflate已启用。 这个网站说我的网站是gzipped:http://www.whatsmyip.org/http-compression-test PageSpeed仍然说:“使用gzip或deflate压缩资源可以减少通过网络发送的字节数。 “ – user2035638 2013-02-22 23:25:42

回答

0

在上面的示例代码中,没有为html内容指定扩展名,例如.php

我通常通过mimetype而不是文件扩展名来管理gzip,例如,

<IfModule mod_filter.c> 
    AddOutputFilterByType DEFLATE application/atom+xml \ 
    etc 

查看https://github.com/h5bp/html5-boilerplate/blob/master/.htaccess获取完整列表。

+0

谢谢!有效。 – user2035638 2013-02-25 19:21:49