Advertisement

http研究之旅:expires

阅读量:
http研究之旅:expires
  • expires可以控制get请求的时候对于资源的有效期
复制代码
    // server.js
    router.get("/home",async ctx=>{
    // ctx.set("Cache-Control","max-age=10")
    ctx.set("Expires",new Date(Date.now()+60000)+"")
    console.log("access...")
    ctx.body = data
    })
    
    
      
      
      
      
      
      
      
    
    代码解释
复制代码
    // demo.js
    var time = Date.now()
    ajax.get("http://localhost:3000/home").then(function(data){
    console.log(data)
    console.log(Date.now() - time)
    })
    
    
      
      
      
      
      
      
    
    代码解释

观察到将expires字段赋值为new Date(Date.now() + 60, 0)后, 其有效期设定为持续一分钟. 检查响应头信息(Response Headers): 即61分钟的时间间隔. 检查响应头信息(Response Headers):

在这里插入图片描述
  • 在expires设置的有效期间内,http请求不会真正向服务器发起请求,而是直接从缓存中获取数据
  • expires 是通过 设置资源的有效期来实现http的缓存控制

全部评论 (0)

还没有任何评论哟~