How can I force clients to refresh JavaScript files?

JavascriptWeb DevelopmentFront End Technology

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]
raja
Published on 18-Jan-2018 11:48:08
Advertisements