← Back to Node.js performance map
📨
Node.js Performance

HTTP Cache Headers

Set Cache-Control, ETag, Vary, and compression from Node.

headers

Detailed Description

HTTP cache headers let Node control how browsers and CDNs reuse responses. Correct Cache-Control, ETag, and Vary headers can remove entire network responses.

Use long caching for hashed static assets and shorter stale-while-revalidate policies for API responses that can tolerate brief staleness.

Mental Model

request
-> etag/cache-control
-> 304 or cached response

When To Use

  • ->Reduce repeated API and asset downloads
  • ->Let browsers and CDNs cache safely
  • ->Improve TTFB and bandwidth usage
Tools: compression, express.static, ETag, stale-while-revalidate
headers.js

Live Editor

Loading...

Output

Run code to see output...