2013-02-22 82 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