Service Worker Sample: Custom Offline Page

Available in Chrome 40+

This sample demonstrates basic service worker registration. During the installation step, a custom "Sorry, you're offline." page is cached. The service worker handles all fetch requests for HTML pages (ignoring other requests), and if fetching an HTML page fails due to a network error, it will instead return the cached "offline" page.

Try disconnecting from your network, and then use this link to revisit this page with a cache-busting URL parameter appended—this ensures that the browser's HTTP cache doesn't fulfill the service worker's fetch() (which would prevent the offline response).

Visit chrome://inspect/#service-workers and click on the "inspect" link below the registered service worker to view logging statements for the various actions the service-worker.js script is performing.