Ensure that JavaScript files or CSS files are refreshed for each new version

We can add into references to JS or CSS files from HTML:

<SCRIPT TYPE="text/JavaScript " SRC="FileName.js?v=<%=AssemblyVersionNumber()%>">

The attribute does nothing other than trick the browser into thinking that the .js file must be retrieved from server for new version instead of cached .

You can write your own AssemblyVersionNumber() function or use my function from My SystemHelper class. like the following:

SystemHelper.GetAssemblyVersion(Assembly.GetExecutingAssembly())

Idea from http://www.thescripts.com/forum/thread165240.html

Note that it could be  problems, if head element has runat="server" attribute.

Also consider to reduce number of CSS and JS files.

posted @ Friday, October 19, 2007 11:50 AM

Print

Comments on this entry:

# re: Ensure that JavaScript files or CSS files are refreshed for each new version

Left by Ashwath at 11/2/2007 11:12 PM
Gravatar
In the .aspx file i am unable to get AssemblyVersionNumber() from the Intellisense. Can you please help me how should i get that?

Thank you so much...!
-Ashwath

# re: Ensure that JavaScript files or CSS files are refreshed for each new version

Left by Michael Freidgeim at 11/3/2007 12:15 AM
Gravatar
I've updated the post to add reference to http://geekswithblogs.net/mnf/articles/87855.aspx#GetAssemblyVersion

Your comment:



 (will not be displayed)


 
 
 
Please add 6 and 2 and type the answer here:
 

Live Comment Preview:

 
«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678