Hey everyone! I just released Kirby Service Worker, a plugin that brings service worker caching to Kirby with a focus on performance, flexibility, and ease of configuration.
Why service workers matter for performance
The first visit to your site loads everything from the network — that’s unavoidable. But the second visit? With a service worker in place, your CSS, JS, fonts, and images are served straight from the local browser cache, bypassing the network entirely. We’re talking sub-millisecond asset delivery. No request leaves the browser. No DNS lookup. No server round-trip. No waiting. Just instant.
On fast connections, this is already a noticeable improvement. On slow or unreliable networks (mobile data, public Wi-Fi…), this difference is night and day. Your returning users get a near-native app experience regardless of their connection quality.
And when they go fully offline? Instead of a blank browser error page, they can still navigate cached content and see a proper offline fallback page you control.
Default behavior out of the box
Even with zero configuration, the plugin already applies sensible caching defaults:
- Images & fonts (png, jpg, jpeg, svg, webp, avif, woff, woff2, eot, ttf, otf) →
cacheFirst, cache name:images - Scripts & stylesheets (js, css) →
cacheFirst, cache name:assets - HTML navigation requests →
networkFirst, cache name:pages - Everything else (unmatched GET requests) →
cacheFirst, cache name:site
From the second visit onwards, your static assets are served locally at full speed. No tuning needed to get started.
Available rules for cache:
cacheFirst— Serve from local cache immediately; fetch from network and update cache if not found.networkFirst— Try the network first; serve from cache if offline or unreachable. Best for pages where fresh content matters.staleWhileRevalidate— Return the cached version instantly, then silently refresh it in the background. Great for content that changes occasionally.networkOnly— Always fetch from network, no caching at all.destruct— Special mode: unregisters the service worker entirely and forces all clients to reload. Useful for removing the worker from a site that no longer needs it.
Would love to hear your feedback! If you run into issues or have ideas for improvements, feel free to open an issue or PR on GitHub.