Have you cleared you cache? - Reduce unwanted caching - ASP.NET MVC VIEW HELPERS

One of the most common things we have to suggest to clients when we are failing to find common ground on the looks and functionality of  a developed site is: “Have you cleared your browser cache?”..familiar?

And sure enough 10 -15 secs later (or depending how long it’s been this the client has last done it) the cache is cleared and you are both now looking at the same CSS changes or be it javascript changes that where made.

Now to try and reduce this, here at wiliam we developed an MVC url helper that effectively appends the build number to the url request to make it unique, pretty simple concept that is relatively easy to implement and reuse.

The code for the helper class is as follows: 

It must be noted that consideration had to be made under what properties in assemblies are considered safe in medium trust environments. With the help of Phil Haack’s advise this was achieved: http://haacked.com/archive/2010/11/04/assembly-location-and-medium-trust.aspx

 After implementing the helper class in your desired view you just call the helper function on any of your resource references



 The result:


Pretty effective hey. Now I cannot take the wrap for this as this the work of my fellow talented colleagues here at Wiliam, Pete N, who was the mastermind behind the idea, then further refined by our Technical director Matt C.