Recommended cache management method?

I am looking to force update JS / CSS dependencies.

Will <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> for this, or will it only result in updating the content inside the page itself?

+4
source share
3 answers

No, it controls only the current document. If you don’t want ugly URIs with random query strings, then it’s time to configure your server. Assuming Apache:

 # mod_expires directives: # enable expires/max-age headers and set default to 0 seconds from last access time ExpiresActive On ExpiresDefault A0 # configure ExpiresByType on your specific types, eg ExpiresByType text/css A0 # mod_headers directives: # send variety of no-cache directives, should cover any quirky clients and gateways Header set Cache-Control "max-age=0, private, no-cache, no-store, must-revalidate, proxy-revalidate, no-transform" Header set Pragma "no-cache" # enclose this in <Files> directive for specific file eg <Files *.js> 

These directory groups will also work in configurations for each directory ( .htaccess files) (in the case of a host with a common environment), given the following requirements:

  • AllowOverride FileInfo valid
  • mod_headers or mod_headers

If both options are enabled - note that the groups overlap on max-age , you want to remove it from Header and use finer control using ExpiresXXXX . The described setting is quite common for a shared hosting environment, so ask the server administrator or try it yourself (it will return 500 Internal Server Error if the corresponding module is not enabled or has no effect if .htaccess processing .htaccess not enabled)

+3
source

You can use the server side language to add a timestamp to each file attachment:

 <?php $timestamp = time(); ?> <link href="shell.css?timestamp=<?=$timestamp?>" rel="stylesheet" type="text/css" /> 

I found that meta cache tags do not work consistently in a cross browser, so this is my approach if I need to force something to reload on the update page.

+4
source

The above answer works, although I most likely will use ?version=1 at the end, so it will cache when there are no changes. Configuring web server cache policies is also effective.

This is a good article about explaining caching for web pages: http://www.mnot.net/cache_docs/

+3
source

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


All Articles