Home

Awesome

Magento Cachebuster

Cachebuster is a Magento module which facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN, Varnish, etc using best practices outlined within the HTML5 boilerplate community.

See section "Filename-based cache busting" in: https://github.com/h5bp/server-configs-apache/blob/2.14.0/dist/.htaccess#L968

URLs affected:

Overview

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:

Example uses

Installation

Configuration

This module is configured via the "System" configuration section:

System -> Configuration -> Advanced -> System -> Cachebuster Settings

Note: Behavior only takes affect on the frontend, admin area static file urls are not processed

mod_rewrite configuration

The following mod_rewrite rules need to be enabled for your store when using this module, potentially via .htaccess file or Virtualhost definition.

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

If you are using the default media .htaccess file which routes missing URLs through Magento's get.php for downloadable products you will also need to add these rules to your .htaccess file in the /media/ directory.

Note: This rewrite condition in the media directory will break the protection provided by downloadable products for the extensions listed. If your store sells downloadable products with one of the above extensions you will likely need to tweak these conditions.

nginx configuration

For nginx you will need to add a rule like the following to your site definition.

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

License

Licensed under the Apache License, Version 2.0