Javascript 如何将版本号添加到HTML文件(不仅仅是css和js文件)

Javascript 如何将版本号添加到HTML文件(不仅仅是css和js文件),javascript,html,css,caching,version,Javascript,Html,Css,Caching,Version,许多人使用css和js文件上的版本号来强制在发布更新时在网页上加载非缓存版本: CSS示例: <link rel="stylesheet" type="text/css" href="style.css?v=2017-03-17"> <script type="text/javascript" src="js/myscript.js?v=2017-03-17"></script> JS示例: <link rel="stylesheet" type

许多人使用css和js文件上的版本号来强制在发布更新时在网页上加载非缓存版本:

CSS示例:

<link rel="stylesheet" type="text/css" href="style.css?v=2017-03-17">
<script type="text/javascript" src="js/myscript.js?v=2017-03-17"></script>

JS示例:

<link rel="stylesheet" type="text/css" href="style.css?v=2017-03-17">
<script type="text/javascript" src="js/myscript.js?v=2017-03-17"></script>

我注意到,通过向css/js文件添加版本号,web浏览器也将从头开始加载HTML文件(css/js文件从中引用),而不使用缓存版本


这是否足以确保HTML文件在所有web浏览器中从头开始显示,或者是否有方法将版本号设置为HTML文件,以确保新更新的HTML文档不会从浏览器的缓存中加载?

通常,浏览器始终采用较新版本的HTML

如果要阻止任何缓存,可以使用以下技巧:

跨most应用程序工作的正确最小标题集 重要浏览器:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
HTML

<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
PHP

header('Cache-Control: no-cache, no-store, must-revalidate');
header('Pragma: no-cache');
header('Expires: 0');
ASP

Response.addHeader "Cache-Control", "no-cache, no-store, must-revalidate"
Response.addHeader "Pragma", "no-cache"
Response.addHeader "Expires", "0"
ASP.NET

Response.AppendHeader("Cache-Control", "no-cache, no-store, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Expires", "0");
RubyonRails

response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '0'
烧瓶上的蟒蛇

resp.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
resp.headers["Pragma"] = "no-cache"
resp.headers["Expires"] = "0"
谷歌围棋

responseWriter.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
responseWriter.Header().Set("Pragma", "no-cache")
responseWriter.Header().Set("Expires", "0")
资料来源: