对于Woocommerce网站,在.htacess中设置Expires Header是一个糟糕的主意吗?

时间:2018-11-19 09:05:46

标签: .htaccess woocommerce expires-header

我已将以下内容添加到我的.htacces文件中,以便设置各种文件类型的到期时间。速度对我的woocommerce网站的影响是巨大的-它正在飞速发展。一切似乎都正常。

但这肯定不是一个好主意,因为如果缓存了所有脚本文件,缩略图等,那么在编辑购物车/回头客等方面事情应该无法正常工作?

这似乎太简单了?

# Optimize cache-control
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType text/html "access plus 3 days"
    ExpiresByType text/xml "access plus 1 seconds"
    ExpiresByType text/plain "access plus 1 seconds"
    ExpiresByType application/xml "access plus 1 seconds"
    ExpiresByType application/rss+xml "access plus 1 seconds"
    ExpiresByType application/json "access plus 1 seconds"
    ExpiresByType text/css "access plus 1 week"
    ExpiresByType text/javascript "access plus 1 week"
    ExpiresByType application/javascript "access plus 1 week"
    ExpiresByType application/x-javascript "access plus 1 week"
    ExpiresByType image/x-ico "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType application/pdf "access plus 1 month"
  <IfModule mod_headers.c>
       Header unset ETag
       Header unset Pragma
       Header unset Last-Modified
       Header append Cache-Control "public, no-transform, must-revalidate"
       Header set Last-modified "Tue, 1 Nov 2018 10:10:10 GMT"
  </IfModule>
</IfModule>

1 个答案:

答案 0 :(得分:2)

在htaccess中设置所有过期时间可能会破坏购物车功能。发生这种情况时,客户无法从购物车中移除产品或更新购物车,因为购物车将继续显示旧内容。但是,您可以设置一些过期时间。参见下面的示例。

#Woocommerce friendly expires
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "access plus 1 month"
    #
    ExpiresByType image/jpg  "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif  "access plus 1 year"
    ExpiresByType image/png  "access plus 1 year"
    ExpiresByType text/css   "access plus 1 month"
    #
    ExpiresByType text/javascript        "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/x-javascript      "access plus 1 month"
    #
    ExpiresByType image/x-icon "access plus 1 year"
</IfModule>