İlknur ÖzcomartSeaCodeTREN

Blog

What is a PWA and how does offline work?

· Web Development

Three pieces are enough to install a website like an app and open it without internet.

A Progressive Web App (PWA) is a set of techniques that lets a website be installed on the home screen and open even without a connection. It has three parts: a web app manifest, a service worker and HTTPS.

The manifest

The manifest is a small JSON file that defines the app’s name, icons, colours and start address. The browser reads it when it offers “Install”. Icons must be the right size; KADRAN’s first icons were the wrong size and I had to regenerate them.

The service worker

A service worker is a script that sits between the page and the network. On install it caches the app’s files and answers requests from the cache when there is no internet. For KADRAN I tested offline start-up in a real Chrome by switching the network off and reloading the page.

The update problem

The first service worker I wrote served everything from the cache, so users kept seeing the old version even after a new one was published. Now a version number is generated from the content of every file, and the design asks the user before switching to a new version. I have not yet verified this update flow with an automated test.

Limits

Some PWA features are limited in iOS Safari and behaviour can differ from Chrome. I have only tested KADRAN in Chrome; trying it on an iPhone is one of the next steps.

PWAservice workerofflinemanifest

Next post