Automatic Versioning & “Cache Busting”

Implemented a CDN/caching layer but haven’t had time to get the versioning of assets worked out properly? Try some basic “cache-busting” using a querystring parameter which gets updated each time you build:

Update AssemblyInfo.cs to end with an asterisk (“*”):

[assembly: AssemblyVersion("1.0.0.*")]

Create a little helper method:

    public static class AppHelper
    {
        private static string _version;
        public static string SiteVersion()
        {
            return _version ?? (_version = 
                        Assembly.GetAssembly(typeof (HomeController))
                        .GetName().Version.ToString());
        }
    }

And use this value in static file references:

<img src="/img/[email protected]()" alt="Logo" />

Which will render something like:

<img src="/img/logo.png?v=1.0.0.20123" alt="Logo" />

This number will change with every build, so should force retrieval of updated static – cached – content.