Monday, September 15, 2014

?v=1.2.3 ...or something similar could be bolted onto the end of file paths in your HTML calling out to .css and .js files in your application.

If you increment the version number as you increment the version, when you roll out code to production, it will jog the cache of users and allow them to have the latest/greatest without being frozen in the past. One way to do this with Razor markup would be like so:

<script src="~/Scripts/Whatever.js?v=@Utilities.RetrieveVersionNumber()"></script>

 
 

On the C# side we could have a static method like this:

public static string RetrieveVersionNumber()
{
   return System.Reflection.Assembly.GetExecutingAssembly().GetName()
         .Version.ToString();
}

 
 

If the version seems to come back as 0.0.0.0 all the time, this is probably only happening in your local environment. The 0.0.0.0 should be replaced with a real number when you view the deployment to production's HTML.

No comments:

Post a Comment