I'm struggling with this for a while now, whenever I upload a script to my website, it doesn't show up until I press Ctrl + F5 or any other alternative, I know it works but if this website of mine gets a publicity, its not like I can tell all the people to go on a computer and press Ctrl+F5 or something, its dumb, I want it to be like all the other websites, I press refresh, (not ctrl+f5) and all the new updates are loaded! if there is some sort of HTML, CSS, code that could help will be well appreciated! Thanks in advance.
Asked
Active
Viewed 442 times
1
-
Possible duplicate of [How to force the browser to reload cached CSS/JS files?](https://stackoverflow.com/questions/118884/how-to-force-the-browser-to-reload-cached-css-js-files) – Heretic Monkey May 19 '19 at 12:47
1 Answers
1
Instead of
<script src="script.js">
you could use
<script src="script.js?version=1">
By increasing the number 1
each time you upload a new script, you are bypassing the cache.
Instead of 1
, you could also create a random number in backend. For instance in PHP:
<script src="script.js?version=<?= time(); ?>">

Reza Saadati
- 5,018
- 4
- 27
- 64
-
Thank you! I have not learned javascript yet, but I put ?version=1 in here, and each time I edited the browser and ran it on my other console, it showed up.. so thank you a lot! it worked like a charm – DarkHorrorOfThirdEye May 19 '19 at 14:16