DEV Community

Cover image for What I learned shipping a service worker for 360 offline file tools
Aniruddha Adak
Aniruddha Adak Subscriber

Posted on

What I learned shipping a service worker for 360 offline file tools

I build OpenFile, a free and open source set of 360+ file tools (PDF, images, video, audio, fonts, archives) that run fully in the browser tab. Nothing gets uploaded. A few weeks ago I made it work offline as an installable PWA, and this post is the honest list of what went right and wrong.

The problem with caching 360 tools

A normal PWA caches a shell and some assets. OpenFile has tools that pull in big WebAssembly modules, for example ffmpeg for video and a PDF engine. If I cache everything on first visit, the first load becomes huge. If I cache nothing, the app is useless on a plane.

What I ended up doing

  1. Precache only the app shell and the tool index. That keeps the first install small.
  2. Cache each tool's code and WASM on first use, with a cache first strategy. After you open Merge PDF once, it works with no network.
  3. Version the cache by build hash, and delete old caches on activate. This stopped users from seeing a half old, half new app.
  4. Keep heavy work in Web Workers so the page stays smooth while a 200 MB video is processed.

Mistakes I made

  • I forgot that some browsers evict cache under storage pressure. Now I ask for persistent storage when the user installs the app.
  • My first update flow silently kept the old version for days. A small "new version ready, reload" prompt fixed that.
  • Range requests for audio and video need special handling in a service worker, or seeking breaks offline.

Why bother

Privacy is the main reason. When files never leave the device, there is no server to trust. Offline support is the bonus: it proves the claim. If it works with airplane mode on, nothing is being uploaded.

You can try it here: https://openfile-studio.vercel.app/
Source (MIT): https://github.com/aniruddhaadak80/OpenFile
Short demo: https://youtu.be/cfftdAUJwp4

If you have dealt with caching big WASM files in a service worker, I would like to hear what worked for you.

Top comments (0)