How can I guarantee that the latest version of my javascript code is loading for the client?

We have a client with thousands of users (who use Internet Explorer) and a large number of javascript files that improve the work with our product.

The problem I am facing is that at any time when we update one of these scenarios , there is no way to find out if the client sees the latest version . What we need to do is tell our client to do a hard update (ctrl + f5) before viewing any changes. Obviously, this approach is not ideal.

I know that browser caching is based on the URL, so you can use something like

  <script src = 'myScript.js? ver = 1.2'>

to get around this problem, but this is not an option for us.

I was hoping there was some kind of header property or something similar that we could use to tell IE not to cache these scripts.

Any ideas?

+4
source share
2 answers

Everything you need to know about the cache http://www.mnot.net/cache_docs/

http://www.mnot.net/cache_docs/#CACHE-CONTROL <- HTTP header

+2
source

You can also specify the name of the file itself, as jQuery does:

<script src='myScript-v1-2.js'> 

Then each time you revise the script, you click on the version number and change the pages containing it to indicate the name of the new script. It is safe and cached, but it still allows your viewers to get the maximum benefit from caching and does not require server configuration changes for the .js file.

A complete solution typically involves setting a relatively short caching time for your host web page, and then allowing various resources (style files, JS files, images, etc.) to have longer caching periods for maximum caching. Anything with fingerprints can have a very long cache life. See the link fabianhjr posted about ways to set the host web page cache lifetime. This can be done on the web page itself ( <meta> settings) or in the http headers through the server.

If you turn off caching for your script file (which probably should be done at the web server level for the script file), then all your viewers will lose their caching advantage and you will lose bandwidth and memory savings when caching. If you use a common .JS file on many pages (a common design template), your viewers will see slower performance on each page.

+3
source

Source: https://habr.com/ru/post/1386137/


All Articles