Menu

Making a static file tool site work offline with a service worker
📰

Making a static file tool site work offline with a service worker

DEV Community: javascript·Pocket PDF·about 11 hours ago
#mEw1rh2A
#devtojavascript#devto#dev#worker#cache
Reading 0:00
15s threshold

A static website doesn't have to stop working when the internet connection disappears.

I wanted PocketPDF to keep working after its first load, including when someone opens it somewhere with no connection.

That meant building an offline strategy around a service worker.

The important distinction is that a service worker isn't just a way to cache the homepage. It needs to understand which resources are essential, which can be downloaded later, and which should never be stored.

Start with the application shell

The first thing I wanted available offline was the application itself.

That includes the HTML, CSS, JavaScript needed to navigate the site, and the basic resources required to open the tools.

These are relatively small files and make sense to precache.

The vendor libraries are another important part of the application shell.

If a tool depends on a local JavaScript library, having the interface cached but not the library doesn't help much.

For example, a PDF tool needs its PDF-related…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.