示例响应头: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)

发表评论 取消回复