http概念简讲(1)-缓存

172 阅读1分钟

流程

浏览器先去请求资源如果缓存里边不存在直接请求存在的话看看有没有过期,没过期直接用,过期了请求服务器资源是否一致,一致304,不一致200缓存新资源

强缓存

  • expire 服务端到期时间
    缺点是客户端改了时间就不准
  • cache-control no-store 不缓存 no-cache 走协商缓存
    public 代理服务启缓存
    private 代理服务器不缓存
    max-age保存的是剩余到期时间
  • 优先级 cache-control优先于expire

协商缓存

  • last-modified跟last-modify-since 缺点:单位是秒,一秒内变化不能识别
  • etag跟if-none-match 缺点:服务端生成etag慢
  • 优先级 etag>last-modifed