- It doesn’t work for me!
- Thanks, works!
The browser caches the script file for an undeterminable amount of time, and the new one isn’t loaded until it expires or is forced down the drain. So what about our users? They might experience the same thing. The usual solution is simple - just append a variable in a form of a random set of characters to the URL. Change this:
or this (for automation):
The problem with this method is that now the script file will never be cached, or rather, reloaded every time a user visits the page, unless he loses interest, goes away, and then comes back to check out what’s new, and than realizes, like “Wow…it’s still the same second?! Cause I noticed the script file hasn’t reloaded. Man, I left like ages ago. I should really lay off the E.”
So we never really used this and just let the Nature take its course. But then it came to me…
This function returns the change time of a file, the script.js file in this case. Ladies and gentlemen, the page will from now forth automatically force reload of a script file only when it has been changed.