Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force refresh client js from server side?

Here is the case:

I get a js to monitor web ads.Because of the browser cache,when i update js on server side,js on client side will not be refreshed immediately.How could i force refresh client js as soon as i update js on server side?

p.s. Add version number strategy is not useful in my case.

like image 533
Allerson Avatar asked Oct 22 '25 05:10

Allerson


1 Answers

Simple strategy - add a version number as a query string to your js files, and change the number. This will cause the browsers to fetch your js files again -

<script src="mysource.js?version=123"></script>

Whenever you change your script on the server, change this version number in the html too. Or better yet, apply a random number as the version value every time you request this script.

like image 52
MD Sayem Ahmed Avatar answered Oct 23 '25 20:10

MD Sayem Ahmed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!