What's the process of javascript Versioning?

526    Asked by LiamDyer in Java , Asked on Oct 13, 2022

I am currently building a Web application using a LAMP stack that relies on Javascript on the front end. As the app grows and expands, I naturally plan to expand and change the javascript files. I'm concerned that many of our users' computers will cache the files (which I usually want) but I want to be proactive to make sure that new files are grabbed when I update.


The obvious answer seems to be to version the javascript files throughout the application so that edit.js becomes edit.0.3.6.js and can be updated whenever the file changes so a new version is downloaded.


I think that this is the most fail-proof method, but I question if there is an easy way to manage these versioning changes automatically. We use Github to version control all our files.


Answered by Nishi Verma

Another way of javascript Versioning, CSS and other such files (say background images), is to add a parameter on the URL that they link to - for example edit.js?ver=1.


When the version changes, you update the parameter - ver=2. This ensures that it will be re-fetched.

An added bonus is that you can easily search for ?ver= in your source code and possibly do a global replace.



Your Answer

Interviews

Parent Categories