Skip to content

Cache Busting

There is a widely used module available that will handle cache busting out of the box.

https://github.com/gordonknoppe/magento-cachebuster

From the readme:

Quote

The module provides cachebusting by automatically altering the URI created by Magento for static files by adding the timestamp of the file to the filename:

Before: http://www.example.com/js/varien/js.js

After: http://www.example.com/js/varien/js.1324429472.js

Server Config

For the cache busted files to be resolved by your web server you need to update your relevant server config.

Nginx

Inside your main server block (behind Varnish if applicable), add the following.

location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
        try_files $uri $1.$3;
}

If there are file extensions missing from the regex then add them in using a pipe i.e: (...|svg)

Apache

Add the following to your .htaccess or virtualhost definition. This is taken directly from the github page (untested).

<IfModule mod_rewrite.c>

############################################
## rewrite files for magento cachebuster

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpeg|jpg|gif)$ $1.$3 [L]

</IfModule>

Cachebuster plesk

Before activating the module be sure you can test it.
Go to Subscriptions -> [domain name] -> Apache & nginx Settings -> Additional nginx directives
And add the following settings

location ~* (.+)\.(\d+)\.(js|css|png|jpg|jpeg|gif)$ {
    try_files $uri $1.$3;
}
And then test by trying urls.

Troubleshooting

  • If CSS is not loading and when checking the source you see anything like ns/etalage/etalage.1544180074.css, do the following.
  • Firstly check if the module is installed or enabled
  • Flush/clean all caches
  • Check nginx config for the above mentioned settings
  • If everything is ok but it is still not working, turn the module off
  • If the module is turned off and it is still not working it means it is not related to the module
  • If it works, check the module files against the github source and double check configuration