【问题标题】:added following to improve page speed to .htaccess添加以下内容以提高 .htaccess 的页面速度
【发布时间】:2013-08-21 22:39:09
【问题描述】:

我将以下内容输入到 www.localmarketingus.com 的 .htaccess 文件中

<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php|xml|html)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# BEGIN Turn ETags Off
<ifModule mod_headers.c>
  Header unset Pragma
  Header unset ETag
</ifModule>
FileETag None
# END Turn ETags Off    

# BEGIN Compress text files
<ifModule mod_deflate.c>
  <filesMatch "\.(css|js|x?html?|php|xml|html)$">
    SetOutputFilter DEFLATE
  </filesMatch>
</ifModule>
# END Compress text files

# BEGIN Expire Headers
<IfModule mod_expires.c> ExpiresActive On
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/html "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 year"
ExpiresByType application/javascript "access plus 1 month"  
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 1 month"
</IfModule>
#END Expire headers

#BEGIN Vary Accept Encoding
<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
  </FilesMatch>
</IfModule>
#END Vary Accept Encoding

<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
  <filesMatch "\.(ico|jpe?g|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
  </filesMatch>
  <filesMatch "\.(css)$">
    Header set Cache-Control "max-age=604800, public"
  </filesMatch>
  <filesMatch "\.(js)$">
    Header set Cache-Control "max-age=216000, private"
  </filesMatch>
  <filesMatch "\.(x?html?|php)$">
    Header set Cache-Control "max-age=600, private, must-revalidate"
  </filesMatch>
</ifModule>
# END Cache-Control Headers

# BEGIN Remove Last-Modified Header
<ifModule mod_headers.c>
  Header unset Last-Modified
</ifModule>
# END Remove Last-Modified Header

但是,当我运行 GTMetrix 和 PageSpeed 洞察时,它仍然说我需要利用浏览器缓存和变化:接受编码??

是不是我在代码中做错了什么??

谢谢,

【问题讨论】:

    标签: .htaccess caching browser pagespeed


    【解决方案1】:

    请添加:

    #BEGIN Vary Accept Encoding
    <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>
    #END Vary Accept Encoding    
    

    代替:

    #BEGIN Vary Accept Encoding
    <IfModule mod_headers.c>
    <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary: Accept-Encoding
    </FilesMatch>
    </IfModule>
    #END Vary Accept Encoding
    

    您可以在 gtmetrix 上查看我的网站,看看我在“指定变化:Accept-Encoding 标头”测试中的得分为 100%。这是我的网站:http://www.fotoshooting.ro/

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2016-05-31
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 2020-11-07
      • 2018-07-18
      • 2012-03-21
      • 2015-07-24
      • 1970-01-01
      相关资源
      最近更新 更多