COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
56/ 70

Caching and conditional requests

Service workers and offline caching

There is more than one caching layer.

UnderstandStudy an examplePractise

Understand the concept

A service worker can intercept scoped fetches and choose network or Cache API responses. Cache API storage does not automatically reproduce ordinary HTTP freshness behaviour; the application needs a strategy. Network-first, cache-first and stale-while-revalidate have different trade-offs.

Old workers and mismatched assets can cause deployment problems. Design versioned caches, activation and cleanup. Personal offline content after logout is a privacy concern; URL-only keys can expose another account’s data.

Service workers require secure contexts, with local-development exceptions that do not justify production HTTP. Inspect worker/storage state separately from the browser HTTP cache. This course does not register a new worker.

WHEN TO USE IT

Diagnose stale pages after deployment.

COMMON PITFALL

Assuming Disable cache removes all offline behaviour.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
Network response ≠ service-worker response

Inspect the response source in DevTools.

This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.

02 / YOUR TURN

Try it yourself first.

Should personalised offline account data remain after logout?

Show the solution and explanation
Worked solution
Deliberate retention and isolation policy required

Not without a deliberate retention/privacy policy; test account isolation.