Skip to content

[html] 第278天 如何禁止html页面缓存? #1792

Open
@haizhilin2013

Description

@haizhilin2013

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

我也要出题

Activity

PullAndRun

PullAndRun commented on Jan 18, 2020

@PullAndRun

etag

leon0707

leon0707 commented on Jan 19, 2020

@leon0707
<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">
liwudi

liwudi commented on Jan 21, 2020

@liwudi

上面说清楚了如何禁止页面缓存,那我对这几个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,表示过期时间,不进行缓存。

liwudi

liwudi commented on Jan 21, 2020

@liwudi

再额外补充一下,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">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @leon0707@haizhilin2013@PullAndRun@liwudi

        Issue actions

          [html] 第278天 如何禁止html页面缓存? · Issue #1792 · haizlin/fe-interview