设置缓存
response.writeHead(statusCode, [statusMessage], [headers])
res.writeHead(200,{ 'Cache-Control':'max-age=100' });
max-age 决定客户端资源被缓存多久
no-cache 强制进行协商缓存
no-store 不进行缓存
response.setHeader(title, value)
res.setHeader('Content-Type', 'text/html');
备注:文件打包后会生成哈希值,有哈希值的可以用强缓存,因为每一次打包都会生成一个新的哈希值,没有哈希值的就建议使用协商缓存。 writeHead比setHeader优先度要高