I have read lots of article on how to auto-version your CSS/JS files – but none of these really provide an elegant way to do this in ASP.NET MVC.
This link – How to force browser to reload cached CSS/JS files? – provides a solution for Apache – but I’m a little confused how this could be implemented via ASP.NET MVC ?
Would anyone be able to provide some advice how to do this on IIS7 and ASP.NET MVC – so that CSS/JS files automatically have a version number inserted in the URL without changing the location of the file ?
That is, so links come out link this etc presumably using the URL Rewrite or ?
<link rel="stylesheet" href="/css/structure.1194900443.css" type="text/css" />
<script type="text/javascript" src="/scripts/prototype.1197993206.js"></script>
Thx
When faced with this problem I wrote a series of wrapper functions around the
UrlHelper‘sContentmethod:EDIT:
Following the discussions in the comments below I updated this code:
Using these functions in conjunction with the following
rewriterule should work:This article discusses how to create rewrite rules on IIS7.
This code uses the version number of the current assembly as a query string parameter on the file path’s it emits. When I do an update to the site and the build number increments, so does the querystring parameter on the file, and so the user agent will re-download the file.