Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS Module Scripts in more contexts #869

Open
PolariTOON opened this issue Oct 9, 2024 · 0 comments
Open

JS Module Scripts in more contexts #869

PolariTOON opened this issue Oct 9, 2024 · 0 comments
Labels
focus-area-proposal Focus Area Proposal

Comments

@PolariTOON
Copy link

PolariTOON commented Oct 9, 2024

Description

ESM has been available in all major browsers through HTML's <script type="module"> for years now and more recently in Workers and Worklets, however JS execution in browsers is not limited to these contexts.

This issue is about improving interoperability for ESM in contexts where browser support is partial, that is to say, other types of documents (XHTML, SVG) and specialized types of worker (Service Workers).

Contexts without any known integration effort for ESM, such as content scripts, would not be included in this proposal.

Specification

See https://tc39.es/ecma262/#sec-modules for the main spec defining modules though this issue is more about their integration in multiple other consuming specs (see links below)

Additional Signals

Site Breakage and Workaround

Classic JS scripts and JS module scripts (or ESM for short) are two types of scripts with incompatible grammars and different sets of features. While support for some new features (static imports, top-level await...) is restricted to ESM, ESM is not yet available everywhere in browsers, making writing or consuming isomorphic code difficult. For example, one cannot write a module that works in all browsers both in a HTML document, a XHTML document, a SVG document and a Service Worker. Without transpilation, the workaround is often using classic scripts and not benefiting from these newer syntax-enabled features, as they are not really polyfillable and detecting support for them is not straightforward. Of course the other way is not targeting some browsers at all 😢

Integration specs, existing tests, documentation and browser bugs

This issue is about improving interoperability for ESM in contexts where browser support is already partial, such as:

Out of scope features

Contexts without enough signal from browsers to integrate ESM in them would not be included in this effort, such as:

  • scripts executed via WorkerGlobalScope.importScripts(...) in Workers
  • content scripts executed via {browser,chrome}.{scripting,tabs}.executeScript(...) in Web Extensions
  • content scripts defined via the "content_scripts" key in Web Extension Manifests
  • API scripts defined via the "user_scripts.api_script" key in Web Extension Manifests
  • background scripts defined via the "background.scripts" key in Web Extension Manifests
  • dynamic import(...) in Service Workers ( see How should import() work in service workers? w3c/ServiceWorker#1585 )
@PolariTOON PolariTOON added the focus-area-proposal Focus Area Proposal label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus-area-proposal Focus Area Proposal
Projects
Status: No status
Development

No branches or pull requests

1 participant