I'm looking to force refreshes of JS/CSS dependencies.
Will <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
work for that, or will that only force a refresh of the content within the page itself?
You could use a server-side language to append a timestamp to each file being pulled in:
<?php $timestamp = time(); ?>
<link href="shell.css?timestamp=<?=$timestamp?>" rel="stylesheet" type="text/css" />
I've found that meta cache tags don't work consistently cross-browser, so this is my go-to if I need to force-reload something on page refresh.
No, it controls only current document. If you dont want ugly URIs with random query-strings, its the 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 directive groups will work in per-directory configs (.htaccess
files) too (in case of shared environment hosting), given following requirements met:
AllowOverride FileInfo
is in effect mod_expires
or mod_headers
is enabledIf both are enabled - note that groups are overlapping on max-age
, you will want to remove it from Header
and use finer control via ExpiresXXXX
.
Described setup is rather common for the shared hosting environment, so ask server admin or just try yourself (will return 500 Internal Server Error
if corresponding module is not enabled or have no effect if .htaccess
processing is not enabled)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With