Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between importScripts and ES6 modules/import?

I currently implement a front-end along with a service worker. As I require several code pieces for my service worker, I opted to use the importScripts function from the standard.

I really don't get why importScripts was added to this standard as modules became part of the ES6 standard about 3 years ago (although still missing in most browsers, if not using a flag).

Can someone elaborate on this? I assume it's related to the error handling and the like...

like image 728
Pat Mächler Avatar asked Jul 04 '17 09:07

Pat Mächler


1 Answers

After some research the bottomline is, that the specification for importScripts was older than for the ES6 modules. In the long run ES6 modules likely will be supported in Service Workers. As of now it's not supported in Chrome Canary yet, although there is ES6 module support for the front-end since version 60.

like image 98
Pat Mächler Avatar answered Nov 19 '22 14:11

Pat Mächler