缓存 Cache-Control
可缓存性:
public private no-cache
到期:
max-age=<seconds> s-maxage=<seconds> 代理服务器生效 max-stale=<seconds>
重新验证:
must-revalidate proxy-revalidate
其他:
no-store no-transform
这些 Headers 只是建设性的规范,不是强制性的,完全可以不按照此规范操作
Example:
const http = require("http"); const fs = require("fs"); const path = require("path"); http.createServer((request, response)=> { if(request.url === '/'){ const htmls = path.resolve(__dirname, "test.html"); const html = fs.readFileSync(htmls, 'utf8'); response.writeHead(200, { 'Content-Type': 'text/html' }); response.end(html); } if(request.url === '/script.js'){ response.writeHead(200, { 'Content-Type': 'text/javascript', 'Cache-Control': 'max-age=200' }); response.end('console.log("srcipt loaded wwuu")'); } }).listen(8089);