如何将版本号添加到HTML文件(不仅是CSS和JS文件)

斯巴达81

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

CSS示例:

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

JS示例:

<script type="text/javascript" src="js/myscript.js?v=2017-03-17"></script>

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

这是确保在所有Web浏览器中从头显示HTML文件的充分方法,还是有办法为HTML文件设置版本号,以确保不会从浏览器的浏览器中加载新更新的HTML文档。缓存?

马可·萨勒诺

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

如果您希望防止任何缓存,可以使用以下技巧:

适用于最重要的浏览器的正确的最小标头集:

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" />

.htaccess(Apache)

<IfModule mod_headers.c>
  Header set Cache-Control "no-cache, no-store, must-revalidate"
  Header set Pragma "no-cache"
  Header set Expires 0
</IfModule>

Java Servlet

response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);

的PHP

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

均价

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");

Ruby on Rails

response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'
response.headers['Expires'] = '0'

烧瓶上的Python

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

Google Go

responseWriter.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
responseWriter.Header().Set("Pragma", "no-cache")
responseWriter.Header().Set("Expires", "0")

来源:http : //cristian.sulea.net/blog.php?p=2014-01-14-disable-browser-caching-with-meta-html-tags

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何将内部版本号(来自 Jenkins)添加到 jar 文件?

在Windows中将版本号添加到通用文件

动态将版本号添加到目标输出文件(带有grunt)

如何在angular 4中向CSS / JS文件添加版本号?

如何将CSS和JS文件添加到MediaWiki?

如何将内部版本号与可执行文件上的版本号同步?

如何将PHP文件添加到HTML文件

如何使用Laravel Mix将版本号添加到路径?

Node.js和Express:如何将脚本文件添加到ejs文件

如何将CSS添加到.scss文件或主题

如何将文件和正文添加到 MockMvc?

如何将Java Applet添加到HTML文件?

如何将文件添加到/ var / www / html

如何将 JSON 数据添加到 HTML 文件

如何将.js文件添加到Svelte REPL?

如何在Powershell中添加参数以更改文件目的地和版本号

如何防止添加到Chrome搜索引擎中(不仅是默认设置)

如何将属性添加到表单标签本身而不仅仅是 Django 中的字段?

在java中转换PDF文件版本(不仅是标题版本!)

VS Code:如何将HTML文件的所有默认片段添加到react js文件中?

如何全局忽略 git 中的 .idea/ 文件夹(不仅仅是将其添加到 .gitignore)

如何将文件添加到Jar文件中?

如何将特定于版本的文件名添加到 Cordova .apk

如何将CSS文件正确添加到php文件

如何将外部javascript文件添加到目录中的所有html文件中?

如何将自定义 js 文件添加到 css 文件等角度组件

Webpack:如何将JS文件的文件夹添加到捆绑器

如何使用Android Gradle插件的0.14+版本向APK文件添加版本号?

将版本号附加到Proguard映射文件夹中