cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Support import statements in Service Workers

dazy
Making moves

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