如何使用.htaccess压缩谷歌加载速度工具提高页面加载速度?

时间:2015-01-31 13:00:11

标签: html css

如何使用.htaccess压缩谷歌加载速度工具来提高页面加载速度。

1 个答案:

答案 0 :(得分:1)

将以下代码放在.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>


<IfModule mod_headers.c>
   <FilesMatch "\.(js|css|xml|gz)$">
       Header append Vary Accept-Encoding
   </FilesMatch>
   <FilesMatch "\.(ico|jpe?g|png|gif|swf)$">
       Header set Cache-Control "public"
   </FilesMatch>
   <FilesMatch "\.(css)$">
       Header set Cache-Control "public"
   </FilesMatch>
   <FilesMatch "\.(js)$">
       Header set Cache-Control "private"
   </FilesMatch>
   <FilesMatch "\.(x?html?|php)$">
       Header set Cache-Control "private, must-revalidate"
   </FilesMatch>
</IfModule>