A Magento 1.x 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.

Overview

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:

  • /js/
  • /media/
  • /skin/

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

  • Automatically invalidating cache when using Cloudfront CDN (see http://www.aschroder.com/2011/05/magento-and-amazons-cloudfront-cdn-the-easy-way/ for a great how-to)
    • Amazon's Cloudfront CDN can be configured to use an origin server but by it's nature will not refresh your updated file until it's cache time expires or you send an invalidation request using their API.
  • No more browser cache issues (ie. Them: "Where's that CSS change I requested?". You: "Oh, did you hit refresh?")
    • Magento's default .htaccess file uses far-future expires headers, which is good for reducing the number of requests to your server, but also means that even without a CDN you have probably experienced browser cache causing a waste of time on what turns out to be a non-issues.

Installation

  • Copy module files into your application
  • Configure apache with the mod_rewrite rules necessary for resolving the new filenames
  • Enable the module in the Magento configuration

Configuration

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

System -> Configuration -> Advanced -> System -> Cachebuster Settings
  • Enable cachebuster
    • Enables the module behavior which rewrites URLs on the frontend. It is important that your mod_rewrite rules are configured before enabling this setting.
  • File extensions
    • Comma-separated list of file extensions which will be rewritten with timestamp applied. Extensions configured here must be defined in your rewrite rule.

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

Comments
  • Question regarding the regeneration of the timestamp

    Question regarding the regeneration of the timestamp

    Hi,

    I would like to use your module which seems to answer perfectly to my needs.

    However, I have a question regarding the regeneration of the timestamp. I would like my assets' URLs to be regenerated as soon as they have been modified.

    However, I notice than when I flush my cache, the timestamps are not regenerated.

    Hence my question: I'm not sure to understand in the module's logic when are the URLs timestamps regenerated ?

    Thank you in advance

    opened by leiluspocus 5
  • Configurable by directory

    Configurable by directory

    What about configuration for which items in the urlMap are busted?

    For example this way /skin and /js can be in the local filesystem with Apache or Nginx doing the rewrite magic but /media can sit in a S3 bucket or similar - with potentially nothing in-front remapping the file served.

    I believe that for most use cases the media directory has pretty good behaviour by default.

    https://github.com/gknoppe-guidance/magento-cachebuster/blob/master/src/app/code/community/Guidance/Cachebuster/Helper/Data.php#L54

    opened by rjocoleman 4
  • Extension is installed but no system config options

    Extension is installed but no system config options

    I have dropped in the extension files.

    Extension is showing as installed under system > advanced.

    However there is no options available within system config.

    Magento ver. Enterprise 1.14.1.0

    Any ideas why this is?

    opened by pushonrobert 2
  • Error: Extensions must be a non empty array

    Error: Extensions must be a non empty array

    Hi,

    I got this error during updating Guidance_Cachebuster to the lastest version:

    Extensions must be a non empty array
    
    Trace:
    #0 Guidance_Cachebuster/src/app/code/community/Guidance/Cachebuster/Model/Parser.php(35): Guidance_Cachebuster_Model_Parser->setFileExtensions(Array)
    #1 app/code/core/Mage/Core/Model/Config.php(1348): Guidance_Cachebuster_Model_Parser->__construct(Array)
    #2 app/Mage.php(463): Mage_Core_Model_Config->getModelInstance('guidance_cacheb...', Array)
    #3 Guidance_Cachebuster/src/app/code/community/Guidance/Cachebuster/Helper/Data.php(98): Mage::getModel('guidance_cacheb...', Array)
    #4 Guidance_Cachebuster/src/app/code/community/Guidance/Cachebuster/Model/Observer.php(40): Guidance_Cachebuster_Helper_Data->getParser()
    #5 app/code/local/Mage/Core/Model/App.php(1334): Guidance_Cachebuster_Model_Observer->controller_action_postdispatch(Object(Varien_Event_Observer))
    #6 app/code/local/Mage/Core/Model/App.php(1313): Mage_Core_Model_App->_callObserverMethod(Object(Guidance_Cachebuster_Model_Observer), 'controller_acti...', Object(Varien_Event_Observer))
    #7 app/Mage.php(448): Mage_Core_Model_App->dispatchEvent('controller_acti...', Array)
    #8 app/code/core/Mage/Core/Controller/Varien/Action.php(551): Mage::dispatchEvent('controller_acti...', Array)
    #9 app/code/core/Mage/Core/Controller/Front/Action.php(80): Mage_Core_Controller_Varien_Action->postDispatch()
    #10 app/code/core/Mage/Core/Controller/Varien/Action.php(422): Mage_Core_Controller_Front_Action->postDispatch()
    #11 app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
    #12 app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
    #13 app/code/local/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
    #14 app/Mage.php(684): Mage_Core_Model_App->run(Array)
    #15 index.php(87): Mage::run('...', 'store')
    #16 {main}
    

    I saw there was a change in Guidance_Cachebuster_Helper_Data lately which initializes the protected $_fileExtensions = array(); Therefor the check is_null($this->_fileExtensions) is always false and fileExtensions do not get initialized. https://github.com/gordonknoppe/magento-cachebuster/commit/65f661c197881a6fc0af50d20981eb195b5bd122#diff-55a9881a212332774228ad08b74ccffcL33

    So you can either remove the initialization again or change the check, not sure what you prefer :-)

    opened by avoelkl 1
  • add modman file

    add modman file

    I've added a modman file for easy installation directly from your Git repo.

    If you don't know modman you can see more about it here: https://github.com/colinmollenhour/modman/

    opened by rjocoleman 1
Releases(v1.0.1)
Owner
Gordon Knoppe
Gordon Knoppe
Module for integrating Fastly CDN with Magento 2 installations

FASTLY CDN FOR MAGENTO2 DOCUMENTATION Thank you for using the "Fastly CDN module for Magento2" (Fastly_Cdn). This package contains everything you need

Fastly 113 Dec 26, 2022
This Magento extension provides a Real Full Page Caching for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes

This Magento extension provides a Real Full Page Caching (FPC) for Magento powered by Varnish with support of Session-Based information caching (Cart, Customer Accounts, ...) via ESI includes

Hugues Alary 95 Feb 11, 2022
Etc cache - Cache plugin for Textpattern CMS

etc_cache Download | Packagist This Textpattern plugin provides an events-driven cache solution for Textpattern CMS. Textpattern is fast, but when you

null 3 Aug 30, 2020
KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

KodExplorer is a file manager for web. It is also a web code editor, which allows you to develop websites directly within the web browser.

warlee 5.5k Feb 10, 2022
HTML5 Twitter Bootstrap 3.1 Magento Boilerplate Template

Magento Boilerplate A HTML5 Twitter Bootstrap 3.1 Magento 1.8 Boilerplate Template Read the blog post or checkout the demo for more information. Insta

null 531 Dec 8, 2022
Learn to apply best practices as a PHP backend developer

PHP eCommerce Project Here are the things that this repo will cover: Object oriented programming principles and best practices Object oriented session

Muhammad Salah 0 Aug 2, 2022
🎓 Collection of useful PHP frequently asked questions, articles and best practices

PHP.earth documentation These files are available online at PHP.earth. Contributing and license We are always looking forward to see your contribution

PHP.earth 278 Dec 27, 2022
An utility component for XML usage and best practices in PHP

An utility component for XML usage and best practices in PHP

Laminas Project 13 Nov 26, 2022
Pimcore Localized Assets - localize your assets with no duplicating files

Localized assets in Pimcore Pimcore Bundle to localize your assets with same file. Installation composer require lemonmind/pimcore-localized-assets bi

LemonMind.com 7 Aug 31, 2022
A Varnish extension for Magento.

Nexcess.net Turpentine Extension for Magento Turpentine is a full page cache extension for Magento that works with Varnish, a very fast caching revers

Nexcess.net 528 Nov 8, 2022
Rah cache minify - HTML compressor module for rah cache Textpattern CMS plugin

Minify module for rah_cache This is a minify module for rah_cache, a full-page caching solution for Textpattern CMS. Rah_cache_minify will minify HTML

Jukka Svahn 1 Feb 13, 2014
Provides automatic recaching of product URLs within Prerender.io

magento2-prerender-io Provides integration between Magento 2 and Prerender.io, giving the ability for product pages to be automatically recached when

Aligent 2 Jun 28, 2022
Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hosted at PackageCloud.

Phalcon Builder - is a packaging system that make it easy and quick to build Phalcon packages such as rpms, debs, etc. Phalcon's distribution that hos

The Phalcon PHP Framework 26 Oct 7, 2022
A htaccess boilerplate for all Magento Community installations. Features focus on speed, SEO and security.

magento-htaccess A htaccess boilerplate for all Magento Community installations. Features focus on speed, SEO and security. The file should be placed

Creare 114 Sep 18, 2022
Magento2 + Varnish + PHP7 + Redis + SSL (cluster ready)

Docker Magento2: Varnish + PHP7 + Redis + SSL cluster ready docker-compose infrastructure Infrastructure overview Container 1: MariaDB Container 2: Re

Fabrizio Balliano 332 Dec 30, 2022
This extension facilitates the cms editing process in your store.

Magenerds_PageDesigner This extension facilitates the cms editing process in your store. Instead of just a wysiwyg editor you now have a drag and drop

Magenerds 92 Nov 23, 2022
Enabling community-powered extension and improvements of the best time indications given.

Enabling community-powered extension and improvements of the best time indications given.

Digital Markethingz 2 Jun 29, 2022
Gamecom.io - Find the best game, community, mod, or servers for you! Data retrieved from @modcommunity.

A website made by Christian Deacon that helps users find any game, community, mod, or server. All data retrieved by @modcommunity. This website is ope

Christian Deacon 10 Nov 2, 2022