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 (“*”):
[csharp]
[assembly: AssemblyVersion("1.0.0.*")]
[/csharp]

Create a little helper method:
[csharp]
public static class AppHelper
{
private static string _version;
public static string SiteVersion()
{
return _version ?? (_version =
Assembly.GetAssembly(typeof (HomeController))
.GetName().Version.ToString());
}
}
[/csharp]

And use this value in static file references:

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

Which will render something like:

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

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