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

问题描述 投票:0回答:1

我已将以下内容添加到我的.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>
.htaccess woocommerce expires-header
1个回答
1
投票

在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>
© www.soinside.com 2019 - 2024. All rights reserved.