Page 1 of 1

Javascript cache

Posted: Wed Mar 27, 2013 5:36 am
by robhathome2
Morning all

Have come across an issue (that I'm hoping is a lack of understanding on my part) in IE9.

Scenario:

An external javascript is attached to a screen and executed via onchange against various fields. If I change the javascript, clear the browser cache (via safety --> delete browsing history) and restart the browser it still uses the old cached version of the js.

I've investigated on the web and have found this type of deep-seated caching is, it seems, by design. For instance, see http://forums.asp.net/t/1728141.aspx/1

Anyone else experiencing this or have any thoughts? I really do not want to be advising all users to do that kind of js cache clearing when we make a change to the js.

Regards

Rob.

Re: Javascript cache

Posted: Wed Mar 27, 2013 12:04 pm
by Scott Klement
I'm not sure that "Browsing History" contains the JavaScript cache, does it? (I don't use IE very often, so I may be wrong about that.) When I want to clear JavaScript cache, I go into the F12 Developer Tools, then click "Cache", and "Clear browser cache for this domain."

If you want your JavaScript to be reloaded each time the screen is displayed (Note: this can slow things down considerably -- that's why browsers cache the data) then you could do so by adding a random number, or similar, to the URL for the JavaScript. For example (this is off the top of my head and untested) you might set your external js to:

Code: Select all

js: "/yourdir/test.js?rnd=" + Math.random()

Re: Javascript cache

Posted: Thu Mar 28, 2013 4:46 am
by robhathome2
Morning Scott

Thanks for the reply. As for browsing history, I appreciate just deleting the sites visited wouldn't have any impact but it does do things like cookies etc. so I was hoping js cache clear would be accessible from there, as oppposed to a developer menu.

After thinking about it (always a dangerous thing) I'm coming round to having a version number as part of the javascript file name, almost like a file level ID, although it does mean that if I end up with generic functions called all over the place then I'll have to change it in those places to use the new version when I make a change.

Do you see where I'm coming from? I guess that in reality I'm going to experience this more myself as I develop and make constant changes to the js. Once live it shouldn't change that often at all.

I certainly do want caching to be left on - it would just be nice if IE was able to detect a change in the js file (be it modified date etc.) and to automatically refresh as and when needed.

Regards

Rob.

Re: Javascript cache

Posted: Thu Mar 28, 2013 10:12 am
by Scott Klement
A version number would probably work very nicely! good idea.