Computer >> Computer tutorials >  >> Programming >> Javascript

How can I force clients to refresh JavaScript files?


To force clients to refresh JavaScript files, you need to edit the script’s src attribute link.

Add the following to the script’s src link −

?<version>

It means the following will be the JavaScript <script> −

<script src="myfile.js?1500"></script>

In addition, you can achieve this by editing the .htaccess file −

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} \.(bmp|png|gif|css|js)$ [NC]
RewriteCond %{QUERY_STRING} !^(.+?&v50|)v=50[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?v=50 [R=301,L]