Nâng CaoNetwork iconNetwork

Cache-Control headers: no-cache vs no-store vs max-age, ETag và Last-Modified hoạt động thế nào?

Cache-Control headers kiểm soát caching behavior: max-age (duration), no-cache (revalidate before use), no-store (never cache); ETag và Last-Modified cho conditional requests.

Cache-Control directives:
- max-age=3600: cache valid trong 3600 giây, không cần request lại server
- no-cache: cache phải validate với server trước khi dùng (dùng ETag/Last-Modified) — không có nghĩa là 'không cache'
- no-store: không cache ở bất kỳ đâu (sensitive data, banking)
- public: CDN và browser đều có thể cache
- private: chỉ browser cache (không CDN) — response personalized
- s-maxage=86400: override max-age chỉ cho shared cache (CDN)
- immutable: resource sẽ không thay đổi (content-hashed assets) — browser không revalidate

ETag (Entity Tag): server gửi hash của content trong response header. Lần sau client gửi If-None-Match: "hash", server so sánh: nếu match → 304 Not Modified (không gửi body); nếu changed → 200 với body mới.

Last-Modified: tương tự nhưng dùng timestamp thay vì hash — kém chính xác hơn ETag. Best practice: static assets với content hash → max-age=31536000, immutable; HTML/API → no-cache với ETag.

Xem toàn bộ Network cùng filter theo level & chủ đề con.

Mở danh sách Network