Support import statements in Service Workers
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2025 10:37 AM
Most major browsers support the use of ECMAScript import statements in the Service Worker by declaring { type: 'module' } when registering the Service Worker script.
This:
// in main script
navigator.serviceWorker.register("service-worker.js", {
type: "module",
})
Enables:
// in service-worker.js
import "path/to/this.js"
import { that } from 'path/to/that.js'
import * as theOtherThing from 'path/to/theOtherThing.js'
// ...
Unfortunately Firefox does not support this functionality for Service Workers. This was disappointing because I had intended to package my Service Worker code for a notification-based library as ECMA modules.
A similar feature was implemented for Web Workers two years ago.
Is FF actively working on this functionality for Service Workers?
0 REPLIES 0

