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


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


A comma-separated list of DOMString objects representing the scripts to be imported. These paths are relative to html document base URL.

Return value



Imported scripts were not served with a valid JavaScript MIME type (i.e. text/javascript).


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() 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

Browser compatibility

ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
importScriptsChrome Full support 4Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 10.6Safari Full support 4WebView Android Full support ≤37Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 11Safari iOS Full support 3.2Samsung Internet Android Full support 1.0
Strict MIME type checks for importScripts()Chrome Full support 71Edge Full support ≤79Firefox Full support 67IE ? Opera Full support 58Safari No support NoWebView Android Full support 71Chrome Android Full support 71Firefox Android Full support 67Opera Android Full support 50Safari iOS No support NoSamsung Internet Android Full support 10.0


Full support
Full support
No support
No support
Compatibility unknown
Compatibility unknown

See also