frank-dspeed / wintercg-proposal-importScripts

The importScripts() method of the GlobalScope interface synchronously imports one or more scripts into the scope. (inlining)
0 stars 0 forks source link

wintercg-proposal importScripts / importScript

history

this was a tc39 proposal but tc39 will not integrate something that breaks the web so we would need to make this a single url taking function called importScript this algins also with our goals as ECMAScript has no concept of i/o its better to agree on that on the implementer level:

nodejs, justjs, deno, chromium,

Explainer

The importScripts() method of the GlobalScope interface synchronously imports one or more scripts into the scope. (inlining) current implementations: https://html.spec.whatwg.org/multipage/workers.html#dom-workerglobalscope-importscripts-dev

importScripts(...urls) Fetches each URL in urls, executes them one-by-one in the order they are passed, and then returns (or throws if something went amiss).

there is a voting on going to rename this to importScript() and let it only handle a single url to not colide with existing environemnt checks for webworkers

Importent please give comments or up down votes for

Status

Champion(s): champion name(s) Author(s): non-champion author(s), if applicable Stage: -1

Implemented: importScript

Motivation

Why is this important to have in the JavaScript language? sync imports are needed:

Importent Knowleg

ECMAScripts do exist in 2 main Flavors: Scripts and Modules everything that has export {} or import is a module everything else is a Script in Some ECMAScript Engines like NodeJS are more Module Systems Implemented for example .node modules or .cjs out of ECMAScript view this implementations are Scripts.

The ECMAScript Module System ESM is Async by Design but this is about a Sync import Process.

Use cases

Some realistic scenarios using the feature, with both code and description of the problem; more than one can be helpful.

Server-side sync import: Say you want to import a ECMAScript Script. Then, you would normally have to create a file and inline the code from the other file. If it's in the standard, it'd be easier as you can simply create a single file that is referencing the files that contain the codes and executes them in order.

var urls = ['url1','url2']
importScripts(...urls);

Browser-side sync import: browsers do only support sync script imports via Githubissues.

  • Githubissues is a development platform for aggregating issues.