Is setting Expires Header in .htacess a terrible idea for a Woocommerce site?

96 views Asked by At

I have added the following to my .htacces file in order to set the expiry time for the various files types. The speed impact on my woocommerce site has been huge - it's flying now. And everything seems to work.

But surely this is a bad idea as if all the script files, thumbnails etc are cached then things shouldn't work properly one editing the cart / returning customers etc?

It just seems too easy??

# 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

There are 1 answers

0
Andrew On BEST ANSWER

Setting up all of the expires in htaccess can break the shopping cart functionality. When this happens, customers cannot remove products from the cart or update the cart because the cart will continue to show the old contents. However, you can set some of the expires. See my example below.

#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>