A service worker can make a website’s app shell available without a network connection by caching its files and deciding how later requests are answered. Register it from a secure page, cache the files needed to render a useful offline view, and add request strategies that match each resource. The initial visit must finish registering and caching while the device is online; a service worker cannot make a first visit offline work.
What a service worker does—and what it does not
A service worker is a separate, asynchronous worker that can intercept network requests and use the Cache API to return saved responses. MDN describes service workers as “proxy servers that sit between web applications, the browser, and the network (when available)” in its Service Worker API overview. It has no access to the page’s DOM, so it cannot directly update visible page elements. The page and worker communicate through browser APIs and messages when needed.
Offline support is not automatic just because a worker is registered. You choose which requests to save, when to use saved responses, and what to show when neither the network nor a cache has the answer. A cached page can still display information but cannot perform server-dependent actions unless the site has separately implemented offline data storage and synchronization.
Before you start: use a secure context and choose the worker’s scope
Service workers are available only in secure contexts. Production sites need HTTPS; browsers treat localhost as secure for development. An ordinary HTTP deployment on a public host will not be able to use the API. See MDN’s secure-context guidance.
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- 𝐑𝐨𝐚𝐦 𝟔 𝐀𝐗𝟏𝟓𝟎𝟎 𝐝𝐮𝐚𝐥-𝐛𝐚𝐧𝐝 𝐬𝐩𝐞𝐞𝐝𝐬 - Wi-Fi 6 Speeds up to 1,201 Mbps (5 GHz) and 300 Mbps (2.4 GHz) for up to 60 devices simultaneously. Actual Wi-Fi speeds vary based on source bandwidth, environment, distance to devices, and obstacles. ◇§
- 𝐏𝐨𝐫𝐭𝐚𝐛𝐥𝐞 𝐚𝐧𝐝 𝐝𝐮𝐫𝐚𝐛𝐥𝐞 𝐝𝐞𝐬𝐢𝐠𝐧 - Roam 6 AX1500 is a pocket-sized travel router compactly designed for trips and adventures, featuring a 1 Gbps WAN/LAN port and a 1 Gbps LAN port for reliable wired connectivity.
- 𝗦𝗲𝗰𝘂𝗿𝗲 𝗪𝗶-𝗙𝗶 𝗼𝗻-𝘁𝗵𝗲-𝗴𝗼 - Connects to public Wi-Fi and creates a private, secure network for all your devices. Supports multiple devices at once, ideal for hotels, Airbnbs, airports, and even home use. VPN connectivity enables secure remote work.
- 𝐌𝐮𝐥𝐭𝐢𝐩𝐥𝐞 𝐰𝐚𝐲𝐬 𝐭𝐨 𝐜𝐨𝐧𝐧𝐞𝐜𝐭 - (1) Router Mode: Connects to public Wi-Fi, ISP, or phone (USB tethering). (2) AP/RE/Client Mode: Adds WiFi to wired setups, extends WiFi, or connects wired devices wirelessly.
- 𝐎𝐮𝐫 𝐜𝐲𝐛𝐞𝐫𝐬𝐞𝐜𝐮𝐫𝐢𝐭𝐲 𝐜𝐨𝐦𝐦𝐢𝐭𝐦𝐞𝐧𝐭 - TP-Link is a signatory of the U.S. Cybersecurity and Infrastructure Security Agency’s (CISA) Secure-by-Design pledge. Advanced security is integrated into the device’s design, development, and ongoing maintenance.
Put the worker file at a URL whose directory covers the pages it should control. A worker at /sw.js can normally control pages throughout the site; a worker in a subdirectory is limited to that directory and its descendants unless the server sets an appropriate scope header. Register the root worker from page JavaScript:
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.catch((error) => console.error('Service worker registration failed:', error));
});
}
The leading slash makes the registration URL root-relative. If the site is hosted under a path rather than at the domain root, adjust the worker URL and cached paths to match that deployment.
Precache a small, useful app shell during installation
Registration causes the browser to download and evaluate the worker, then run its lifecycle. The first lifecycle event is install, as MDN notes in Using Service Workers. This is the normal place to cache the minimum set of files needed for a meaningful offline screen: the page or app shell, its CSS and JavaScript, essential images, and an offline fallback document.
Rank #2
- 【AC1200 Dual-band Wireless Router】Simultaneous dual-band with wireless speed up to 300 Mbps (2.4GHz) + 867 Mbps (5GHz). 2.4GHz band can handles some simple tasks like emails or web browsing while bandwidth intensive tasks such as gaming or 4K video streaming can be handled by the 5GHz band.*Speed tests are conducted on a local network. Real-world speeds may differ depending on your network configuration.*
- 【Easy Setup】Please refer to the User Manual and the Unboxing & Setup video guide on Amazon for detailed setup instructions and methods for connecting to the Internet.
- 【Pocket-friendly】Lightweight design(145g) which designed for your next trip or adventure. Alongside its portable, compact design makes it easy to take with you on the go.
- 【Full Gigabit Ports】Gigabit Wireless Internet Router with 2 Gigabit LAN ports and 1 Gigabit WAN ports, ideal for lots of internet plan and allow you to connect your wired devices directly.
- 【Keep your Internet Safe】IPv6 supported. OpenVPN & WireGuard pre-installed, compatible with 30+ VPN service providers. Cloudflare encryption supported to protect the privacy.
Give the cache a versioned name so a later release can use a new cache without mixing incompatible files with the previous version. event.waitUntil() tells the browser that installation depends on the asynchronous cache operation completing; if a required file cannot be cached, installation can fail rather than leave an incomplete shell.
Recommended Free Tools
const CACHE_NAME = 'site-shell-v1';
const APP_SHELL = [
'/',
'/index.html',
'/styles.css',
'/app.js',
'/images/logo.png',
'/offline.html'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))
);
});
Every path in the list must actually exist and be accessible to the page’s origin. Keep this list deliberately small: adding large images or files that the offline screen does not need increases storage use and can make installation more fragile.
Choose a request strategy that fits each resource
Use a fetch handler to intercept requests and call event.respondWith() with the response to return. Static assets that change only when you deploy are often a good fit for cache-first. Frequently changing pages or API responses are often better served network-first, with a cached fallback where it makes sense.
Rank #3
- 𝐑𝐨𝐚𝐦 𝟔 𝐀𝐗𝟏𝟓𝟎𝟎 𝐃𝐮𝐚𝐥-𝐁𝐚𝐧𝐝 𝐓𝐫𝐚𝐯𝐞𝐥 𝐑𝐨𝐮𝐭𝐞𝐫 - Delivers fast Wi-Fi 6 speeds (1201 Mbps on 5 GHz, 300 Mbps on 2.4 GHz) for uninterrupted video streaming, downloading, and online gaming all at the same time. Actual Wi-Fi speeds vary based on source bandwidth, environment, and distance to devices.
- 𝐒𝐞𝐜𝐮𝐫𝐞 𝐖𝐢-𝐅𝐢 𝐎𝐧-𝐓𝐡𝐞-𝐆𝐨 - Connects to public Wi-Fi and creates a private, secure network for all your devices. Supports multiple devices at once, ideal for hotels, Airbnbs, airports, and even home use. VPN connectivity enables secure remote work. This is not a Mi-Fi device or mobile hotspot.
- 𝐂𝐨𝐧𝐧𝐞𝐜𝐭 𝐀𝐧𝐲𝐰𝐡𝐞𝐫𝐞, 𝐀𝐧𝐲 𝐖𝐚𝐲 - Offers (1) Router Mode for Ethernet or USB (phone) tethering connections, (2) Hotspot Mode for secure access to public WiFi , and (3) AP/RE/Client Mode to extend WiFi, add WiFi to wired setups, or connect wired devices wirelessly.
- 𝐏𝐨𝐫𝐭𝐚𝐛𝐥𝐞 𝐚𝐧𝐝 𝐃𝐮𝐫𝐚𝐛𝐥𝐞 𝐃𝐞𝐬𝐢𝐠𝐧 - The Roam 6 AX1500, measuring a compact 4.09 in. × 3.54 in. × 1.10 in., is a pocket-sized travel router perfect for your next trip or adventure.
- 𝐌𝐮𝐥𝐭𝐢𝐩𝐥𝐞 𝐰𝐚𝐲𝐬 𝐭𝐨 𝐩𝐨𝐰𝐞𝐫 𝐲𝐨𝐮𝐫 𝐫𝐨𝐮𝐭𝐞𝐫 - Power the Roam 6 via its USB-C port using the included adapter or any 5V/3A PD power source, like a power bank.
| Strategy | Freshness | Offline reliability | Latency and bandwidth | Good fit |
|---|---|---|---|---|
| Cache-first | May serve an older cached copy until the cache is updated. | Strong when the requested resource was cached earlier. | Can avoid a network request when a cached response exists. | Versioned CSS, JavaScript, logos, and other stable assets. |
| Network-first | Uses a current network response when one is available. | Works offline only if a suitable cached response exists as fallback. | Usually waits for the network before falling back; uses the network when online. | Content or API data where freshness matters more than instant cache delivery. |
Cache-first for static files
This example checks the cache first, then fetches a missing resource and saves a successful response. It leaves failed requests and unsuccessful HTTP responses uncached.
self.addEventListener('fetch', (event) => {
const request = event.request;
const url = new URL(request.url);
if (request.method !== 'GET' || url.origin !== self.location.origin) {
return;
}
event.respondWith((async () => {
const cached = await caches.match(request);
if (cached) return cached;
const response = await fetch(request);
if (response.ok) {
const cache = await caches.open(CACHE_NAME);
await cache.put(request, response.clone());
}
return response;
})());
});
Cache-first deliberately trades freshness for availability and speed. If an asset changes, use a new cache version and ensure the page references the corresponding assets; otherwise the worker may keep returning an older cached file.
Network-first for changing pages or data
For requests where current content matters, try the network and save a successful response for later. If the request fails, use a cached response; if there is none, return a clear fallback rather than an unhandled network error.
Rank #4
- 【DUAL BAND WIFI 7 TRAVEL ROUTER】Products with US, UK, EU, AU Plug; Dual band network with wireless speed 688Mbps (2.4G)+2882Mbps (5G); Dual 2.5G Ethernet Ports (1x WAN and 1x LAN Port); USB 3.0 port.
- 【NETWORK CONTROL WITH TOUCHSCREEN SIMPLICITY】Slate 7’s touchscreen interface lets you scan QR codes for quick Wi-Fi, monitor speed in real time, toggle VPN on/off, and switch providers directly on the display. Color-coded indicators provide instant network status updates for Ethernet, Tethering, Repeater, and Cellular modes, offering a seamless, user-friendly experience.
- 【OpenWrt 23.05 FIRMWARE】The Slate 7 (GL-BE3600) is a high-performance Wi-Fi 7 travel router, built with OpenWrt 23.05 (Kernel 5.4.213) for maximum customization and advanced networking capabilities. With 512MB storage, total customization with open-source freedom and flexible installation of OpenWrt plugins.
- 【VPN CLIENT & SERVER】OpenVPN and WireGuard are pre-installed, compatible with 30+ VPN service providers (active subscription required). Simply log in to your existing VPN account with our portable wifi device, and Slate 7 automatically encrypts all network traffic within the connected network. Max. VPN speed of 100 Mbps (OpenVPN); 540 Mbps (WireGuard). *Speed tests are conducted on a local network. Real-world speeds may differ depending on your network configuration.*
- 【PERFECT PORTABLE WIFI ROUTER FOR TRAVEL】The Slate 7 is an ideal portable internet device perfect for international travel. With its mini size and travel-friendly features, the pocket Wi-Fi router is the perfect companion for travelers in need of a secure internet connectivity on the go in which includes hotels or cruise ships.
async function networkFirst(request) {
const cache = await caches.open('site-runtime-v1');
try {
const response = await fetch(request);
if (response.ok) {
await cache.put(request, response.clone());
}
return response;
} catch (error) {
const cached = await cache.match(request);
if (cached) return cached;
return new Response('You are offline, and this content is not available yet.', {
status: 503,
headers: { 'Content-Type': 'text/plain; charset=utf-8' }
});
}
}
self.addEventListener('fetch', (event) => {
const request = event.request;
const url = new URL(request.url);
if (request.method !== 'GET' || url.origin !== self.location.origin) {
return;
}
if (url.pathname.startsWith('/api/')) {
event.respondWith(networkFirst(request));
}
});
These are starting patterns, not a universal routing policy. Decide deliberately which URLs belong in each strategy and how the page should handle a fallback. Do not cache every response indiscriminately: API data can become stale, and large or user-specific responses may be inappropriate to save.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Keep app-shell caching and runtime caching separate
Precached files and runtime-cached responses serve different purposes. The shell is a known, small set of assets saved during installation; runtime caching accumulates responses as people use the site. Keeping them in separate named caches makes it easier to update the shell without removing useful runtime data.
| Cache type | When it is populated | Typical contents | Update and failure considerations |
|---|---|---|---|
| Precached app shell | During the worker’s install event. | Essential HTML, CSS, JavaScript, images, and an offline page. | Update the versioned cache when deploying changed assets; missing required files can prevent installation from completing. |
| Runtime cache | As requests occur after installation. | Selected pages or GET responses, such as API data chosen for offline fallback. | Can grow and become stale; cache selectively and define what to do when a resource has never been requested online. |
The Cache API stores request-response pairs, but it is not a complete offline data system. For structured data that must be available offline, IndexedDB is available in the worker context. The worker cannot use synchronous Web Storage such as localStorage.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Best Value
- 𝐏𝐫𝐢𝐯𝐚𝐭𝐞 𝐍𝐞𝐭𝐰𝐨𝐫𝐤 𝐀𝐧𝐲𝐰𝐡𝐞𝐫𝐞 - Roam 7 BE3600 connects to public Wi-Fi and creates a private, secure network for all your devices. Supports up to 90 devices at once, ideal for hotels, Airbnbs, airports, and home use. VPN connectivity supports secure remote work.
- 𝐑𝐨𝐚𝐦 𝟕 𝐁𝐄𝟑𝟔𝟎𝟎 𝐃𝐮𝐚𝐥-𝐁𝐚𝐧𝐝 𝐓𝐫𝐚𝐯𝐞𝐥 𝐑𝐨𝐮𝐭𝐞𝐫 – Delivers up to 2882 Mbps on the 5 GHz band and 688 Mbps on the 2.4 GHz band, supporting smooth streaming, downloads, and gaming for up to 90 devices. ◇ 𝐓𝐡𝐢𝐬 𝐦𝐨𝐝𝐞𝐥 𝐝𝐨𝐞𝐬 𝐧𝐨𝐭 𝐬𝐮𝐩𝐩𝐨𝐫𝐭 𝟔 𝐆𝐇𝐳 𝐁𝐚𝐧𝐝.
- 𝐂𝐨𝐧𝐧𝐞𝐜𝐭 𝐀𝐧𝐲𝐰𝐡𝐞𝐫𝐞, 𝐀𝐧𝐲 𝐖𝐚𝐲 - Offers (1) Router Mode for Ethernet or USB (phone) tethering connections, (2) Hotspot Mode for secure access to public WiFi , and (3) AP/RE/Client Mode to extend WiFi, add WiFi to wired setups, or connect wired devices wirelessly.
- 𝐌𝐮𝐥𝐭𝐢-𝐆𝐢𝐠𝐚𝐛𝐢𝐭 𝐂𝐨𝐧𝐧𝐞𝐜𝐭𝐢𝐯𝐢𝐭𝐲 - 1x 2.5 Gbps WAN and 1x 1 Gbps LAN ports, along with WiFi 7 speeds, enable fast wired and wireless data transmissions.
- 𝐎𝐮𝐫 𝐂𝐲𝐛𝐞𝐫𝐬𝐞𝐜𝐮𝐫𝐢𝐭𝐲 𝐂𝐨𝐦𝐦𝐢𝐭𝐦𝐞𝐧𝐭 - TP-Link is a signatory of the U.S. Cybersecurity and Infrastructure Security Agency’s (CISA) Secure-by-Design pledge. This device is designed, built, and maintained, with advanced security as a core requirement.
Handle updates without leaving users on mixed versions
When the worker script changes, the browser can install a new worker in the background while the previous worker continues controlling open pages. Normally the new worker waits to activate until pages controlled by the old worker are gone. This protects an open page from suddenly receiving a different set of cached files, but it means an update may not take over immediately.
During activation, delete obsolete caches owned by this site. Match cache names precisely so cleanup does not remove data belonging to unrelated features or libraries:
const CURRENT_CACHES = ['site-shell-v2', 'site-runtime-v1'];
self.addEventListener('activate', (event) => {
event.waitUntil((async () => {
const names = await caches.keys();
await Promise.all(
names
.filter((name) => name.startsWith('site-') && !CURRENT_CACHES.includes(name))
.map((name) => caches.delete(name))
);
})());
});
skipWaiting() and clients.claim() can make a new worker activate and control pages sooner, but using them without considering the page’s state can mix old page code with new worker behavior. Use them only when the update experience is designed for that transition—for example, with a deliberate reload or update notice—and test it with open tabs.
Test the offline experience in the right order
Offline behavior depends on a successful online visit first. Test from a clean state so an old cache or already-installed worker does not disguise a setup problem.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →- Serve the site from localhost or an HTTPS origin and open the page online.
- In browser developer tools, clear the site’s storage and reload the page.
- Check that registration succeeds, the worker installs, and the app-shell cache contains every listed file.
- Reload while still online, then switch the developer tools’ network setting to offline and reload again.
- Visit a cached route and an uncached route; verify the cached content or intended fallback appears rather than a blank page.
- Change the worker and cache version, reload, and inspect the worker lifecycle and Cache Storage to confirm the new shell is installed and obsolete caches are removed.
If registration works on localhost but not on a public HTTP URL, the likely issue is the secure-context requirement: production needs HTTPS. If the worker registers but the page is not controlled, check that the worker file’s directory and registered URL cover the page. If installation fails, confirm that every precached path resolves successfully and that the worker can finish its waitUntil() work.
Know the limits of an offline site
A cached page can render offline, but a form submission, purchase, login, or other server operation still needs a network unless you build additional offline queuing and synchronization. That design must address retries, duplicate submissions, data freshness, and conflicts; a simple service worker cache does not solve those problems. Make the interface distinguish saved content from actions that require a connection, and provide a useful fallback for requests that have never been cached.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

