The module type serves roughly the same purpose as the type="module" attribute for the script tag . It tells the browser that the working script that loads is the ES6 module (which is the necessary metadata to know how to parse it and run it, how this article goes in bit ).
You would use it if your work module were an ES6 module (possibly with import statements). It also has a bonus to be able to download an employee from another source, if CORS permits that classical workers cannot (which can be an attractive feature even if you do not use import statements).
From HTML Living Standard - Using the JavaScript module as work :
All of our examples are so far shown to employees who run classic scripts. Instead, workers can be created using module scripts, which have the usual advantages: the ability to use the JavaScript import operator to import other modules; strict strict mode by default; and top-level ads that do not pollute the global area of ββthe employee.
Please note that such module-based workers are subject to various restrictions on cross-content compared to classic workers. Unlike classic workers, module workers can be created using the cross-original script if this script is open using the CORS protocol. In addition, the importScripts () method will automatically fail inside working modules; JavaScript import statement is usually the best choice.
You probably won't use it in production today, as browser support for ES6 modules is not so good.
Alexander O'Mara
source share