I thought I was having an issue with my javascript being cached and not updated even with an updated version tag, like:
我以为我的javascript被缓存了,甚至没有更新的版本标签,比如:
<script type="text/javascript" src="lib/myScript.min.js?v=3"></script>
But I realized that the problem is with my html file is being cached... so the browser doesn't even know there is a new script file.
但是我意识到我的html文件被缓存了……所以浏览器甚至不知道有一个新的脚本文件。
I don't want to disable caching, but isn't there a way to let the browser know it doesn't have the most up-to-date html file? (And is this something I'd put in my html file, or on my apache2 server?)
我不想禁用缓存,但难道没有办法让浏览器知道它没有最新的html文件吗?(这是我在我的html文件中,还是在apache2服务器上?)
3 个解决方案
#1
4
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Answer from Using tags to turn off caching in all browsers?
使用标签关闭所有浏览器的缓存?
#2
2
You can try these meta tags.I think it will solve your problem.
你可以试试这些元标签。我想这能解决你的问题。
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
#3
1
Besides writing explicitly in html, you actually have two better options: ETAG
and Last-Modified
. If your html file is a static file, then apache2 will know how to handle its cache, by default. if it's php, then you will have to handle it in your code, or use some php framework.
除了显式地用html编写外,实际上还有两个更好的选项:ETAG和Last-Modified。如果您的html文件是一个静态文件,那么apache2将默认知道如何处理它的缓存。如果是php,那么必须在代码中处理它,或者使用一些php框架。
Since these two headers are not written in html, browsers don't have to download the whole body of HTTP response, and thus reduce traffic. So I suggest you use them.
由于这两个头不是用html编写的,所以浏览器不需要下载整个HTTP响应,从而减少了流量。所以我建议你使用它们。
I believe a little googling may help.
我相信用谷歌搜索一下会有帮助。
What takes precedence: the ETag or Last-Modified HTTP header?
优先考虑什么:ETag或最后修改的HTTP头?
#1
4
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
Answer from Using tags to turn off caching in all browsers?
使用标签关闭所有浏览器的缓存?
#2
2
You can try these meta tags.I think it will solve your problem.
你可以试试这些元标签。我想这能解决你的问题。
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>
#3
1
Besides writing explicitly in html, you actually have two better options: ETAG
and Last-Modified
. If your html file is a static file, then apache2 will know how to handle its cache, by default. if it's php, then you will have to handle it in your code, or use some php framework.
除了显式地用html编写外,实际上还有两个更好的选项:ETAG和Last-Modified。如果您的html文件是一个静态文件,那么apache2将默认知道如何处理它的缓存。如果是php,那么必须在代码中处理它,或者使用一些php框架。
Since these two headers are not written in html, browsers don't have to download the whole body of HTTP response, and thus reduce traffic. So I suggest you use them.
由于这两个头不是用html编写的,所以浏览器不需要下载整个HTTP响应,从而减少了流量。所以我建议你使用它们。
I believe a little googling may help.
我相信用谷歌搜索一下会有帮助。
What takes precedence: the ETag or Last-Modified HTTP header?
优先考虑什么:ETag或最后修改的HTTP头?