Adding offline support to your site is easier than ever these days thanks to service workers.

I recently added offline support to my blog with a small service worker using a 'stale-while-revalidate' technique that will always serve up a cached resource to the user if available, if not it will fall back to the normal network response. The beauty of this technique is that it always attempts to perform the network response and will cache the up-to-date response for use next time.

NOTE: Make sure you have cache headers appropriately set. I spent a good chunk of time trying to debug why the cache wasn't updating and realised it was due to a high max-age header being set on the resource.

You can get around a misguided max-age issue by implementing some cache-busting within the service worker. When calling out to the network for the resource you can append a random string to force the browser to go to the server to a fresh copy.