ASP.NET MVC cache refresh..

stoymigo

Senior Member
Joined
Dec 11, 2008
Messages
975
Reaction score
26
Hello, I am working on a asp mvc system using Visual studio 2012 and I'd like to know if you know how to solve the following problem.

When I make a change in a javascript file, and run the project, then the javascript file is not refreshed unless I press Ctrl+F5.

How to reload the javascript file and all others automatically because I might miss that the cached version has not been replaced?
Thx
 
thats not a problem it's how the internet works.

what you can do is version your js files by having a whatever.v1.js and a whatever.v2.js forcing the browser to get new files instead of using their cached version.

this is useful to make sure everyone using the site has the newest js files. but during the development of a particular version ctrl f5 is your best friend.

i know vs2013 has browser link which i think can get past this issue. but ive never used it...
 
Last edited:
add a ?v=XXX where XX can be an epoch date, that way the javascript file is always refreshed/downloaded

whatver.v1.js is a bad solution. Rename the file anytime you make a change :confused:
 
Hello, I am working on a asp mvc system using Visual studio 2012 and I'd like to know if you know how to solve the following problem.

When I make a change in a javascript file, and run the project, then the javascript file is not refreshed unless I press Ctrl+F5.

How to reload the javascript file and all others automatically because I might miss that the cached version has not been replaced?
Thx


Have a look at this link and read it in detail from start to finish.

Your browser is caching the JS, so you need a way to ensure it is updated if the source changes. If you use bundling on MVC, you get the scripts and style sheets added to a unique url. When you change any of those bundled assets, the runtime regenerates the key and hence, the browser will not cache it.

You could enable this feature during dev, however, it would not help you with debugging. Bundling should certainly be added in for production.
 
As it's been noted already, the caching happens on the IIS server, browser etc.

You could leverage off of Bundles

MVC / VS.NET 2012 allows you to add your js files to bundles, they automatically minify/compress/gzip it and it actually maintains a version too. That way when you rebuild and launch a new version of your site or file, it automatically rebuilds and let all caches know that this file has changed

http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification
 
Top
Sign up to the MyBroadband newsletter
X