Disable JavaScript caching in Google Chrome

Can I disable JavaScript caching in Google Chrome? I disabled the cache in the developer tools (Ctrl-Shift-I), but it still caches JS files ... Using Chrome version 20.

+6
source share
1 answer

For development purposes, you can use Ctrl + R or Ctrl + F5, they should not send cache headers, therefore they request a resource from the server, and not cache. This is called Hard Refresh.

But don't expect users to use Ctrl + R / F5, if you want to always send an unused resource to a user, use the Cache buster ( Google search for cache>

Web browsers use a URL to determine if they know a resource, so accessing the same URL will cause the web browser to check if it has accessed that URL before allowing it to send a specific resource header that it has, and check if the resource has changed on the server.

Caching devices is a name that is said to be used to iterate over the cache and always reload the resource. The following is an example of a cache omitted URL:

<script type="text/javascript" src="/static/js/some.js?bust=12356"></script> 

Note: this can be any name, not "bust".

A good way to always have a unique bust is to use the time of the Unix era (the number of seconds elapsed since 1.1.1970, each language offers you some function to get this number), another widely used solution is some random number. Thus, the browser will always receive the resource from the web server.

+8
source

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


All Articles