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.

Return value



Exception Description
NetworkError 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

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
importScriptsChrome Full support YesEdge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes
Strict MIME type checks for importScripts()Chrome Full support 71Edge ? Firefox 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 Yes


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

See also


Document Tags and Contributors

Last updated by: chrisdavidmills,