The importScripts() method of the WorkerGlobalScope interface synchronously imports one or more scripts into the worker's scope.
self.importScripts('foo.js');
self.importScripts('foo.js', 'bar.js', ...); A comma-separated list of DOMString objects representing the scripts to be imported.
None.
| Exception | Description |
|---|---|
| NetworkError | The MIME type of an imported script is not a valid JavaScript MIME type. |
If you had some functionality written in a separate script called foo.js that you wanted to use inside worker.js, you could import it using the following line:
importScripts('foo.js'); importScripts() and self.importScripts() are effectively equivalent — both represent importScripts() being called from inside the worker's inner scope.
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'importScripts()' in that specification. | Living Standard |
| Desktop | ||||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
| Basic support | Yes | Yes | Yes | Yes | Yes | Yes |
| Mobile | |||||||
|---|---|---|---|---|---|---|---|
| Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
| Basic support | Yes | Yes | Yes | 4 | Yes | Yes | Yes |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts