I'm using a third party JavaScript library in a website with 20+ HTML pages each with its own JavaScript and CSS file. But the problem is if a new version is available to the library then, I have to go through all the HTML files to edit the version number. How to maintain the same version of the library in all the webpages?
Asked
Active
Viewed 117 times
2
-
That is one reason not to use static HTML files, but some kind of content management system; or at least an included file for any HEAD markup. – feeela Mar 25 '19 at 13:06
-
You could do something like Laravel does it already with its blade files... – Aaron3219 Mar 25 '19 at 13:07
-
If you have no way at all to template your site and have to include the file on each page. Then rename the file to something without a version number and put the version number as a comment in the file at the start so you can easily find it. This way you only need to replace the file and no need to rename. This is a last resort kind of thing – Huangism Mar 25 '19 at 13:09
-
If you have a web server, you could keep the Javascript there and whenever the user logs in to get that page, and their JS is auto updated. A variable version number within the script tag might work? – Compiler v2 Mar 25 '19 at 13:16
-
could you provide some code? The HTML file maybe? – Compiler v2 Mar 25 '19 at 13:17
-
@Compilerv2 im using firebase libraries Cloud firestore, RTDB, Storage i have added script tags in header to each HTMT file. – Vamsi Smart Mar 25 '19 at 13:24
-
I'm unfamiliar with Firebase, but I understand your problem. Can you provide some of your HTML code, showing the script tags? Also, instead of updating the JS for all of your 20+ HTML pages, you should utilize a server to update it in one place. So when the user logs on to the website, they all have the same version. – Compiler v2 Mar 25 '19 at 13:28
2 Answers
4
- If you're using any kind of server-side processing before serving the pages, you can have a separate file that contains just the (shared)
script
tags that need to be loaded and include that file with each of the HTML pages. - If not, editors like VS Code (
Ctrl + Shift + H
) can do Find/Replace across all files in a project. - Finally, you could omit the version number from the script file names (you'll just have to be aware of how the caching works - people may not get the new file right away).

Mike B.
- 1,422
- 12
- 8
-
Can you please explain last point lets say i'm using can we omit version number 5.9.1? – Vamsi Smart Mar 25 '19 at 13:14
-
1For the last option, you would need to have your own copy of the file somewhere so that you could control the name/path, and put it somewhere that you can reach without having to specify the 5.9.1 part. Like `./shared_scripts/firebase/firebase-app.js` or something. – Mike B. Mar 25 '19 at 13:17
2
If you are not using any kind of server-side processing, you could create your own javascript file loader that comes from your own file and loads the external javascript. So you only have to change the external part in one file that gets included in all your other html pages.
Something like this: JavaScript - function to load external JS files is needed

Der Alex
- 718
- 3
- 16