Fe-interview: [html] 第278天 如何禁止html页面缓存?

Created on 18 Jan 2020  ·  4Comments  ·  Source: haizlin/fe-interview

第278天 如何禁止html页面缓存?

我也要出题

html

Most helpful comment

上面说清楚了如何禁止页面缓存,那我对这几个meta属性进行说明一下:

Cache-Control

表示缓存控制,no-cache,no-store,must-revalidate,都表示不缓存的意思。
不过,Cache-Control是http1.1支持的。目前大多数http传输都是1.1的版本。

Pragma

值设置为no-cache,和Cache-Control的意义是一样的。
区别:Pragma是http1.0支持的写法,所以这一句是为了兼容老版本的http传输协议。

Expires

值设置为0,表示过期时间,不进行缓存。

All 4 comments

etag

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

上面说清楚了如何禁止页面缓存,那我对这几个meta属性进行说明一下:

Cache-Control

表示缓存控制,no-cache,no-store,must-revalidate,都表示不缓存的意思。
不过,Cache-Control是http1.1支持的。目前大多数http传输都是1.1的版本。

Pragma

值设置为no-cache,和Cache-Control的意义是一样的。
区别:Pragma是http1.0支持的写法,所以这一句是为了兼容老版本的http传输协议。

Expires

值设置为0,表示过期时间,不进行缓存。

再额外补充一下,meta标签一些其他比较重要的设置。

window-target

表示用于显示窗口的设定

<meta http-equiv="Window-target" content="_top">

说明:这是一道常见的面试题,如何防止别人通过iframe嵌入自己的网页?

content-Type

用来定义页面使用的语言。

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">

viewport

用来表示移动端友好,让pc端展示的网页,在移动端也能有比较好的展示效果。

<meta name="viewport" content="width=device-width,initial-scale=1.0">
Was this page helpful?
0 / 5 - 0 ratings