W3cubDocs

/DOM

WorkerGlobalScope.importScripts

The importScripts() method of the WorkerGlobalScope interface synchronously imports one or more scripts into the worker's scope.

Syntax

self.importScripts('foo.js');
self.importScripts('foo.js', 'bar.js', ...);

Parameters

A comma-separated list of DOMString objects representing the scripts to be imported.

Return value

None.

Exceptions

Exception Description
NetworkError The MIME type of an imported script is not a valid JavaScript MIME type.

Example

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.

Specifications

Browser compatibilityUpdate compatibility data on GitHub

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

See also

WorkerGlobalScope

© 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