I have a java/spring web app application that uses a fair bit of javascript as part of the gui. However when I release a new version I am manually, well using my ide's refactoring tool, renaming javascript files if they are edited.
This avoids users getting stuck with an inpatible/out of date javascript file that doesn;t include new functionality... or worse breaks with the newer jsp/html.
Is there a better way to add versioning to javascript files and their scrip tag references ?
I have a java/spring web app application that uses a fair bit of javascript as part of the gui. However when I release a new version I am manually, well using my ide's refactoring tool, renaming javascript files if they are edited.
This avoids users getting stuck with an inpatible/out of date javascript file that doesn;t include new functionality... or worse breaks with the newer jsp/html.
Is there a better way to add versioning to javascript files and their scrip tag references ?
Share Improve this question edited Mar 5, 2014 at 15:19 NimChimpsky asked Mar 5, 2014 at 15:13 NimChimpskyNimChimpsky 47.3k60 gold badges201 silver badges315 bronze badges2 Answers
Reset to default 7You could do something like this. Which enforce the browser to load the new updated javascript.
yourscript.js?version=1234567890
On
<script type="text/javascript" src="yourscript.js?version=1234567890"> </script>
Every time you update the javascript file just update the number like yourscript.js?version=1234567891
How does it work?
Browser does interpret this as a new file every time when you'll update with new version number. So older javascript files would not cached.
A good practice is to insert a hash (or part of it) in the file name. The way I use it, it does a md5 on the file content (after minifying and piling all files together).
You end up with a file name looking like script.H6oylsUj9sWn.min.js
for instance.
That way, if the file didn't change, the hash stays the same and the client doesn't have to re-download the file.
Beside of that my piler also generates my server side script that insert them in my html. You can of course automate all that.