Browser Cache Buster

v1.0.0.0

26/01/2013

Elency Solutions, Lee Crowe

Introduction

Browser Cache Buster provides developers with the ability to prevent CDN's (Content Delivery Networks), browsers and general infrastructure from caching changed web site assets such as images, css and javascript files.

This is done by renaming assets to include an MD5 hash of the asset file content and updating all relevant source files within the web site code base.

Usage Instructions

Firstly you will need to download the BrowserCacheBuster.exe and it’s dependent assemblies from codeplex.  The executable is a windows executable and requires .Net framework v4.0 to be installed on the executing machine.

When running the BrowserCacheBuster application without any arguments you will be shown all of the available arguments that can be passed in as shown in the image below.

When running the cache buster there are a number of required and non required arguments.  There are also two command types.

Get Unique asset and source file extensions

The command below will allow you to see all of the unique file extensions within the defined asset and source folders:

BrowserCacheBusting.exe -c:1 -afp:c:\dev\web\assets -srfp:c:\dev\web -sfp:c:\dev\web

This can be useful to understand which file extensions should be included/excluded.

Cache Bust

There are many command line arguments available but all of the arguments can also be defined in the application configuration file BrowserCacheBustiner.exe.config.  If defined these would become the application defaults but can be overridden via the command line arguments.

When Cache Busting you will need to supply all of the required arguments.  But you can also supply various filters for file paths, file names and file extensions which can be used to include/exclude files and directories.

The command below will hash all asset files which have the following extensions .js,.css,.jpg and .png.  It will also update all source files excluding files with a .jpg or .png extension..  The arguments are also telling the cache buster to delete the old versions of asset files.

BrowserCacheBusting.exe -c:0 -afp:c:\dev\web\assets -sfp:c:\dev\web -srfp:c:\dev\web -afef:.js,.css,.jpg,.png -afeft:1 -sfef:.jpg,.png -sfeft:0 -d:1

The screen dump of the executed command is below:

Other Useful Information

  1. As there are many options available it will be probably be worth you backing up your code before toying with the Cache Buster.  You can then play around will all of the available options to your hearts content safe in the knowledge that if something goes wrong you can always revert back.
  2. There are 2 command line options available for the asset root folder path (-arfp:) and the source root folder path (-srfp:).  If these are defined the following placeholders can be passed into all of the other file path arguments and there values will be replaced with the relevant asset or source folder paths.