Skip to content

Make images smaller using best-in-class codecs, right in the browser.

JavaScript

Correct service worker name

Jake Archibald722f1c806c7b
diff --git a/rollup.config.js b/rollup.config.js
index a16d32bd..9d5026a0 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -112,7 +112,9 @@ export default async function ({ watch }) {
plugins: [
{ resolveFileUrl, resolveImportMeta },
OMT({ loader: await omtLoaderPromise }),
- serviceWorkerPlugin({ output: 'static/sw.js' }),
+ serviceWorkerPlugin({
+ output: 'static/serviceworker.js',
+ }),
...commonPlugins(),
commonjs(),
resolve(),
diff --git a/src/copy/sw.js b/src/copy/sw.js
new file mode 100644
index 00000000..b5767ccf
--- /dev/null
+++ b/src/copy/sw.js
@@ -0,0 +1,14 @@
+// I accidentally shipped with the wrong service worker name.
+// This picks up users that still might be using that version.
+// We'll be able to delete this file eventually.
+
+addEventListener('install', () => {
+ skipWaiting();
+});
+addEventListener('activate', async () => {
+ await self.registration.unregister();
+ const allClients = await clients.matchAll({
+ includeUncontrolled: true,
+ });
+ for (const client of allClients) client.navigate('/');
+});