HTML Modules
- Category
- JavaScript
- Type
- New or changed feature
- Status
- In development (Chrome In development)
- Intent stage
- Start prototyping
WPT details: Edge are working on a full set of tests that will be upstreamed to the web-platform-tests-suite.
Summary
HTML Modules allow web developers to package and access declarative content from script in a way that allows for good componentization and reusability, and integrates well into the existing ES6 Modules infrastructure.
Motivation
The introduction of ES6 Script Modules has provided several benefits for javascript developers including more componentized code and better dependency management. However, easy access to declarative content has been a consistent limitation with Script Modules. For example, if one wants to pack a custom element definition in a module, how should the HTML for the element's shadow tree be created? Current solutions would involve generating it dynamically (document.createElement or innerHTML), but it would be preferable to simply write HTML and include it with the module. With HTML Modules this will be possible. There is clear demand for this functionality in the developer community -- ideas pertaining to HTML Modules have resulted in a great deal of developer and browser implementer engagement. HTML Imports were proposed (and implemented in Chromium) as a solution, but they were developed independently of ES6 Modules and have several limitations: - Global object pollution - Parse blocking with inline script - Independent of dependency resolution infrastructures between HTML Imports and HTML Modules - Non-intuitive import pass through Integrating HTML Modules into the existing ES6 Module system, rather than creating it as a standalone component, will address these gaps.
Standards & signals
- Firefox: Positive — Expressed support at TPAC 2018. See also this response to our initial proposal and this page summarizing Mozilla's stance on HTML Imports and the status update it links to that indicates their desire to pursue a solution better aligned with ES modules.
- Safari: Positive — Safari: Expressed support at TPAC 2018.
- Web developers: Mixed signals
- Tracking bug: https://crbug.com/990978
Ecosystem
- Web Platform Tests: https://wpt.fyi/results/?q=html-modules
- Chrome Platform Showcase: https://chrome-platform-showcase.paulkinlan-ea.deno.net/features
- GenDN reference: https://gendn.paulkinlan-ea.deno.net/features
- chrome.dev demos search: https://www.google.com/search?q=site%3Achrome.dev+HTML%20Modules
- MDN Web Docs: https://developer.mozilla.org/en-US/search?q=HTML%20Modules
- Baseline status: https://webstatus.dev/?q=HTML%20Modules
Docs: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/HTMLModules/designDoc.md https://github.com/w3c/webcomponents/blob/gh-pages/proposals/html-modules-explainer.md
Explainers: https://github.com/MicrosoftEdge/MSEdgeExplainers/blob/master/HTMLModules/explainer.md