admin管理员组文章数量:1277395
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?
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?
3 Answers
Reset to default 4You 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- Either
mod_expires
ormod_headers
is enabled
If 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 mon 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)
The above answer works, though I'd probably rather use a ?version=1
at the end, so that it will cache when there are no changes. Also setting the webservers cache-policies is effective.
This is a good article on explaining caching for webpages: http://www.mnot/cache_docs/
本文标签: javascriptRecommended cache control methodStack Overflow
版权声明:本文标题:javascript - Recommended cache control method? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741240860a2363948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论