Build the web app like an appliance

Offline-first PWA architecture that plans for the network vanishing, not just slowing: caching, cache warming and sync patterns that make a web app feel native.

Prabir Singh, profile photoPrabir Singh·
·Updated ·13 min read
Editorial illustration: A small portable device continues showing saved check marks beside an unplugged network cable.
In this article
  1. 01A PWA is a web app that stops needing the web
  2. 02The service worker is the whole idea
  3. 03Caching strategy is the architecture
  4. 04Render on the server, so there is something to cache
  5. 05Warm the cache before you need it
  6. 06Data that survives the network
  7. 07Make it installable, and keep it fresh
  8. 08When a PWA is the right call, and when it isn't
  9. 09An offline drill that tells you something useful
  10. 10Frequently asked questions
  11. 11Turn it on, it works

Your toaster does not check the Wi-Fi before it makes toast.

That is the whole standard. An appliance does its job whether the world around it cooperates or not. Most web apps fail it within one lift ride.

There are two kinds of bad network, and most apps only plan for one. Slow is the polite one. Slow gets a spinner, a skeleton screen, a progress bar, and eventually it arrives. The other kind is gone: the basement, the metal exhibition hall, the train in a tunnel. Gone never arrives. And an app built for slow, dropped into gone, does the worst thing it can do at the worst moment. It shows an error to a person who was halfway through something.

A Progressive Web App is what you build when you decide the second kind of network is the one that matters. Here is how that architecture actually holds together, from the part doing the real work outward.

A PWA is a web app that stops needing the web

Strip the branding off and a PWA is three plain capabilities stacked on a normal website. None of them is a framework. There is no npm install pwa. They are browser platform features you opt into.

Installable

It sits on the home screen and opens fullscreen, no address bar, no browser chrome. That alone changes how people treat it. A bookmarked tab feels borrowed. An icon on the home screen feels owned.

Offline-capable

Pages it has seen once keep working with the radio off. This is the hard part, and it is most of this article.

Self-updating

It refreshes itself without an app store in the loop. You deploy from your desk and the installed app picks it up. No review queue, no "please update" nag.

The service worker is the whole idea

A service worker is a script that sits between your app and the network as a programmable proxy. MDN describes it exactly that way: a proxy between the app, the browser and the network, built to make offline experiences possible. Once a page is controlled by an active worker, its fetch requests can be intercepted. The first visit and pages outside its scope need separate handling. The worker decides what happens next: answer from a local cache, go to the network, or blend the two.

For controlled pages and prepared content, the worker can make the network optional.

That one indirection is what turns a website into an appliance. Once you own the request, "offline" stops being an error the browser hands you. It becomes a decision you make.

I don't hand-write service workers anymore. Serwist handles registration, precaching and the runtime rules, and it pairs cleanly with Next.js. Still, hold on to the mental model underneath, because the defaults will bite you. They bit me.

Caching strategy is the architecture

Here is the part that looks like a config detail and is secretly the entire design. When a request hits the worker, which strategy answers it?

StrategyWhat it doesUse it for
NetworkFirstWaits on the network, falls back to cacheFreshness-sensitive reads, with an explicit timeout and fallback.
StaleWhileRevalidateServes the cache instantly, refreshes in the backgroundPublic reads where stale content is acceptable; scope personalised data carefully.
CacheFirstServes the cache, touches the network only on a missBig immutable assets: video, fonts, a brochure PDF.

The web.dev Offline Cookbook is still the clearest field guide to these patterns if you want the long version.

Why NetworkFirst betrays you on a flaky connection

Most offline setups default pages to NetworkFirst, and on stuttering LTE that is the single worst choice. It waits on the network before it serves the cache. When the signal hiccups, the wait times out, and the fallback fires the offline screen. The page was sitting in the cache the entire time.

So the user sees "You're offline" for one second on a page that was always there. They do not care that it recovered. They saw the error. I hit exactly this bug on a showroom kiosk, mid-conversation with a buyer, and that second does not come back.

Invert the default

Switch pages to StaleWhileRevalidate. Serve the cached copy now, quietly refresh it in the background if the network happens to be up. The offline screen becomes a true last resort instead of a symptom of a slow first byte.

The video trap nobody warns you about

Here is the one that genuinely surprised me. A <video> element does not download a file in one go. It sends byte-range requests, and those partial responses come back as HTTP 206, which a cache will not store. So a video can play perfectly online and be completely absent offline. Unplug, and it is gone.

The fix on the kiosk was a small function that fires one normal full-file fetch in the background the first time a video plays, stores the whole thing, and lets a range plugin slice the cached copy for every future request. Playback never notices. The cache just fills up behind it.

Render on the server, so there is something to cache

A service worker can cache responses: HTML, scripts, assets and API data. The important question is whether you cached everything the screen needs. This is where your rendering model matters more than most people expect.

A client-rendered page ships as a near-empty shell plus JavaScript that fetches its own data after it loads. Cache only that shell, and offline you have cached a note that says "cook this once you find a stove." A client-rendered app can work offline too, if its scripts and required data are available locally. A server-rendered page arrives as complete HTML with the content already plated, which is exactly what you want to hand a cache.

That is one more reason I render on the server by default. The output is flat and cacheable, with no client fetch left to fail when the signal disappears. For what the same choices do to load time on a real phone, see the PageSpeed write-up for this site.

Warm the cache before you need it

A cache only helps with pages the user has already visited. People do not move through an app in order. Someone opens the home screen, then jumps straight to the one page nobody pre-loaded, and if the signal dropped in between, that page was never cached.

So you warm it. A small routine runs once after the worker is active, while the device is still online, and quietly fetches every route in the app. On the kiosk that meant all 19 routes, spaced 120 milliseconds apart so the connection barely noticed, re-running whenever the device reconnected.

After successful preparation of the required routes and assets, the planned offline content is available on the device. Not just the pages someone happened to tap first. For a kiosk or a field tool that gets one good connection before it goes dark, this is the difference between "mostly works offline" and "works offline."

Data that survives the network

Reading offline is half the job. The other half is what happens when the user does something offline: submits a form, saves a note, places an order.

Queue the write, tell the truth

The pattern that holds up is a queue with a sync. The submit tries the network first. If it goes through, done. If the request never leaves the device, or the server answers with a 5xx, the write goes into local storage and the UI says the honest thing: saved, and it will send itself when you're back online. A small listener flushes the queue on the browser's online event.

Classify the failure before retrying

Do not endlessly retry invalid input. But not every 4xx means the same thing: a 401 may need a new sign-in, a 409 needs conflict handling, and a 429 may permit a later retry according to the server's instructions. Network failures and some 5xx responses can also leave the outcome uncertain. Use bounded retries and a stable operation key so recovery does not duplicate a write.

Add a layer that fails differently

Redundancy only counts when the layers break for different reasons. On the Garden Vareli kiosk, lead capture had three: the server, the browser queue, and an on-device export staff could download by hand. If the whole cloud went down for an entire event, the leads were still sitting in the tablet in the salesperson's hand.

Make it installable, and keep it fresh

Two smaller pieces finish the appliance.

The manifest

Installability comes from the web app manifest: name, icons, display: standalone for fullscreen, orientation, theme color. Get it right and the app installs with no browser chrome, which is most of what makes a PWA feel native instead of like a tab someone forgot to close.

The update loop

Freshness is the trap nobody thinks about until a stale build is running at a trade show. A fullscreen app can stay open for days without a single page change, so the browser may not notice your new deploy for a long while. The kiosk polls for a new worker every 15 minutes and reloads silently when one takes control. On first install it deliberately does nothing, because there is no old version to replace.

When a PWA is the right call, and when it isn't

A PWA is not a native app with better economics. It is a different tool, and I'd rather tell you that now than after you've built the wrong one.

PWANative (Expo)
Ships asA URL, one codebaseStore builds for iOS and Android
UpdatesThrough the worker lifecycle and cache/update policyStore review, or over-the-air for JS changes
Offline content and captureExcellent, with a service workerExcellent
Background work and rich pushLimited, weakest on iOSFirst-class
Best forKiosks, field tools, internal apps, hardware you don't controlProducts that live on notifications and native gestures

Reach for a PWA when the job is content, capture and presentation that has to survive a bad network. Reach for native when you need deep device integration, reliable background work or rich push. On iOS, PWA support is real and distinctly second-class. If the product lives or dies on notifications, one Expo codebase for both stores is the honest answer, not a web app in a trench coat.

An offline drill that tells you something useful

“Works in airplane mode” needs a few more words. Was the app installed, had that route been visited, and had every asset finished downloading? Try these cases separately:

Starting pointWhat to verify
Fresh browser, no previous visitAn honest network requirement, not a claim of offline readiness
Prepared device, never-opened routeRequired route and assets are available after warming completes
Form sent, response lostRetrying the same operation does not create a duplicate
Session expires while offlineQueue pauses for authentication; it doesn't silently discard the write
Storage fills upThe UI reports that saving failed and offers a recovery path
New app version arrivesExisting unsent work survives the update path

Browser storage is useful, but not a backup contract. Quotas, eviction and user deletion matter; MDN documents the limits. Request persistent storage where appropriate, handle failed writes, and provide a deliberate export or server acknowledgement for valuable records.

For personalised data, define who owns each cached entry and clear it on account changes. Cache-first is a good servant for a public brochure and a terrible excuse for showing the previous user's account. The kiosk case study is a specific deployment, not a universal caching policy.

Frequently asked questions

Do I need a framework to build a PWA?

No. A PWA is a set of browser features, not a library. You need a manifest and a service worker. A toolkit like Serwist just spares you writing the worker by hand and fits neatly into a Next.js build.

Will a PWA work offline on iOS?

Partly. Safari supports service workers and offline caching, so cached pages and playback work. Storage limits are tighter and background features are thin, so test on a real iPhone, never just a desktop browser.

How do I test offline properly?

On the real device, in airplane mode. A desktop browser's "offline" checkbox does not truly cut the service worker's network, so it will cheerfully tell you things work that don't. The only test that counts is the one where the radio is actually off.

Is a PWA slower than a native app?

For the offline-first jobs it suits, no. Serving from cache is a local read, which is often quicker than a native app's first network call. The gap shows up in device integration and background work, not in raw speed.

Why does my offline video play online but vanish offline?

Because video loads through byte-range requests that return HTTP 206, and partial responses don't get cached. Fetch the full file once in the background on first play, store it, then let the worker slice ranges from the cached copy.

Turn it on, it works

A PWA is not a lesser native app. It is the web deciding to keep its promises when the network breaks them. The craft lives in the failure modes: what the app does when the signal drops, when a write can't send, when nobody is standing there to fix it. Own the request, cache with the right strategy, warm what you'll need, queue what you can't send yet, and the happy path takes care of itself.

If you're building something that has to work in a basement, a booth or a tunnel, tell me the constraint you're working inside and I'll tell you straight whether the web can reach it, or whether a native build is the better spend.

Was this useful?

No account needed. One like per browser; click again to undo.

ShareXLinkedInFacebook
Prabir Singh, profile photo

Prabir Singh

Full-stack engineer in Mumbai. Twenty years in sales taught me why people buy; seven years of code taught me how to build what they'll pay for. I still read error messages the way I once read objections: as the most honest feedback of the day. More about me or start a project.

Keep reading