示例响应头:Cache-Control: public, max-age=3600, stale-while-revalidate=86400

ETag: "f1a2-3c4d"

Last-Modified: Wed, 26 Nov 2025 10:00:00 GMT

条件请求(客户端):GET /app.css HTTP/1.1

If-None-Match: "f1a2-3c4d"

If-Modified-Since: Wed, 26 Nov 2025 10:00:00 GMT

服务端返回未变更:HTTP/1.1 304 Not Modified

Cache-Control: public, max-age=3600, stale-while-revalidate=86400

ETag: "f1a2-3c4d"

Node.js 示例:import express from 'express'

const app = express()

app.get('/api/data', (req, res) => {

const etag = '"data-v1"'

res.set('Cache-Control', 'public, max-age=300, stale-while-revalidate=86400')

res.set('ETag', etag)

const inm = req.headers['if-none-match']

if (inm === etag) return res.status(304).end()

res.json({ ok: true, ts: Date.now() })

})

app.listen(3000)

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部