为什么在 html 的 head 部分使用元标记“Pragma”和“Expires”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21797397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 00:56:17  来源:igfitidea点击:

Why use meta tag "Pragma" and "Expires" in head section of html

html

提问by FarwallGhost

Why use meta tag "Pragma" and "Expires" in head section of html like this. Thanks.

为什么像这样在 html 的 head 部分使用元标记“Pragma”和“Expires”。谢谢。

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">

回答by Vainglory07

Using this will disable the browser to cache your webpage.

使用这将禁用浏览器缓存您的网页。

Disabling cache has some valuable advantages.

禁用缓存有一些宝贵的优势。

Like when you update your files on the server, if happened that the browser doesnt have a cached copy of your webpage then it would force itself to load the updated content of your website.

就像您更新服务器上的文件一样,如果浏览器没有缓存的网页副本,那么它会强制自己加载您网站的更新内容。

One of the disadvantage of this is the impact on page downloading. Since you dont have cached copy on your browser, it will always download all of your assets from the server thus affecting time and also consuming bandwidth.

这样做的缺点之一是对页面下载的影响。由于您的浏览器上没有缓存副本,它总是会从服务器下载您的所有资产,从而影响时间并消耗带宽。

Try reading this article.

尝试阅读这篇文章

回答by Jukka K. Korpela

Both tags are meant to prevent browsers from caching the HTML page, and they usually do that. This means that access to the page may be slower especially if it is frequently visited. Probably most commonly, these tags are inserted by people who do not understand how caches work. See Caching Tutorial for Web Authors and Webmasters.

这两个标签都是为了防止浏览器缓存 HTML 页面,他们通常会这样做。这意味着对页面的访问可能会变慢,尤其是在经常访问的情况下。可能最常见的是,这些标签是由不了解缓存工作原理的人插入的。请参阅Web 作者和网站管理员的缓存教程

There are several way to try to prevent caching. These specific tags have no official definition, and they are not conforming according HTML5 CR.

有几种方法可以尝试防止缓存。这些特定的标签没有官方定义,也不符合 HTML5 CR。