Skip to content

http请求缓存小记 #10

@iscarecrow

Description

@iscarecrow

关键词

  • expires/cache-control
  • if-modified-since/if-none-match
  • eTag

如何进行http缓存

304缓存

1.if-modified-since/Last-Modified

client request if-modified-since: time1
server response  Last-Modified: time2
time1 = time2

2.if-none-match/ETag

client request if-modified-since: eTag1
server response ETag:eTag2
eTag1 = eTag2
200缓存

cache-control: max-age = 2592000 (s) (设置缓存时间)
expires: maybe next year

如何不进行http缓存

How to control web page caching, across all browsers?

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

使用场景:隐私数据, api请求

QA

一. 200 OK (from cache) 与304 Not Modified 区别

200 (from cache)
  • request status 为200的情况下并没有发起请求。根据expires/cache-control判断。
  • 回车访问
304
  • 304的情况,http发起了请求。服务器响应。但是并不下载文件。根据if-modified-since/if-none-match确认缓存文件是否存在。
  • 强刷页面

结论:time 200快于304。

cache-control:max-age=0和no-cache的区别

no-cache no-store

other

  • if-modified-since if-none-match priority??
  • if doc need cache ?? maybe no
  • public && private , when to use ?

参考资料

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions