http缓存和各个版本差异理解

2019-10-08  本文已影响0人  木中木

http缓存
我们可以通过设置http头部属性来对资源进行缓存,资源缓存分为强制缓存和协商缓存

app.use(conditional());
app.use(etag());
app.use(resource(path.join(__dirname, './views')));

// app.use(router.routes());
app.listen(3000, '0.0.0.0');
1-1.png

2.last-modified

      const ifSinceModified = req.headers['if-modified-since'];
      const lastModified = stat.ctime.toGMTString();
      if (ifSinceModified === lastModified) {
        res.writeHead('304');
        res.end();
      } else {
        res.setHeader('Content-Type', mime.getType(filePath));
        res.setHeader('Last-Modified', stat.ctime.toGMTString());
      }

缓存的Nginx配置见:https://www.cnblogs.com/wenyule/p/11073277.html
https://www.codercto.com/a/74887.html

image.png

下面讲述http版本差异,http的共同点都是基于tcp协议进行三次握手。

上一篇下一篇

猜你喜欢

热点阅读