Guides

Service workers

Edit this page

To register a service worker:

  1. Place your service-worker file in the public directory (e.g., public/sw.js), making it available at the root URL (/sw.js).
  2. Add registration logic to the client.entry.tsx file.
src/client.entry.tsx
// @refresh reload
import { mount, StartClient } from "@solidjs/start/client";
mount(() => <StartClient />, document.getElementById("app")!);
if ("serviceWorker" in navigator && import.meta.env.PROD) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("/sw.js");
});
}
Report an issue with this page