Service Workers and PWAs: It’s About Reliable Performance, Not “Offline”

A lot of smart folks keep asking me why AppCache isn’t a good enough solution for “offline” and why it was necessary to invent Service Workers. It’s a great question!

Motivated by the regrettably uneven browser support landscape for Service Workers, there’s a real incentive to “just make something work offline” on iOS or old-IE. This phrasing obscures the primary experience difference between native apps and web content: native apps always “boot” when you tap on them. The legacy web, however, can take as long as the TCP timeout (2 minutes in many devices) to end in failure. That’s a looooong time to be looking at a white screen.

But doesn’t AppCache let you cache documents you might want offline? Sort of. Kinda. Ish. Turns out this only works in trivial cases. The issue is that the AppCache design only allows you to do “routing” using the FALLBACK section, and to trigger the FALLBACK URL (which can boot up, inspect it’s environment, and do something custom) the request needs to have actually failed. To handle the general case — a site with an unbounded set of URLs — that means users are waiting on a flaky, slow network for minutes (if they’re patient) before the the router page starts, which might then forward them on to content or a custom offline experience.

“But wait!”, you say, “doesn’t AppCache also allow you to put documents in the cache directly, bypassing all of that?”. Yes, it does, but because of AppCache’s atomic update system and practical limits to storage space, this means that the set of URLs in this list needs to be low and change infrequently. You see this play out, for example, in the AppCache manifests that major Google services like Google Docs generate. These services wind up with major complexity related to creating manifests on a per-user basis and managing the entries in them. Those entries are carefully curated from amongst the entire set of possible URLs to ensure high performance for the entries users are likely to visit offline, but this still leaves everything else at the mercy of network flakiness.

It’s hard to stress enough how much better reliable performance is. Think of it this way: the first load of a native app sucks. It’s gated by an app store and a huge download, but once you get to a point where the app is installed, that up-front cost is amortized across all app starts and none of those starts have a variable delay. Each application start is as fast as the last, no variance. What native apps deliver is reliable performance.

Until Service Workers arrived, it simply wasn’t possible to achieve this and that’s why I designed Chrome’s Add-to-Homescreen prompting behavior to require a Service Worker that responds quickly for the URL listed in the Manifest’s start_url. The heuristic is designed to only promote experiences that are “app-like”; recognizing that a key differentiator between the “old web” and native apps is reliable performance.

Remy Sharp blogged about the experience and expectation differences that we’ve worked hard to bake into Progressive Web Apps. Reliable performance is the most important of these and the reason Progressive Web Apps require Service Workers. It isn’t that “offline” support doesn’t matter — it does — but apps that work well offline are a subset of things that are apps, experiences you can trust to start any time, anywhere, on any connection.

I’ll be speaking more about this at Google I/O in a few weeks, and I’m hugely excited about the ways that the web is going to get better this year; starting with experiences that always work.

3 Comments

  1. Jesse Hattabaugh
    Posted May 5, 2016 at 2:17 pm | Permalink

    Enlightening article. I can see that PWAs are an improvement over AppCache. However I curious what the progressive enhancement best-practices are for trying to support both. Can you recommend any example projects i could look at?

  2. Posted May 5, 2016 at 4:42 pm | Permalink

    Hey Jesse,

    At one point, to explain some of this to co-workers, I wrote a document with the title “AppCache In Your Architecture: Not Even Once“. It wasn’t an exaggeration. Trying to contort your design around AppCache might work if you only have 2 or 3 URLs in your app (total), but for anything bigger, my recommendation is that you just not bother.

    Regards

  3. Posted May 18, 2016 at 7:24 am | Permalink

    your web font family is so clear and pure.i love that