tc39 / proposal-dynamic-import

import() proposal for JavaScript

Home Page:https://tc39.github.io/proposal-dynamic-import/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Synchronous version?

brettz9 opened this issue · comments

This request would need to be limited to dynamic import, but I think it is a real need as long as import is being visited...

Currently modules (as well as modules targeted by your proposal), being run asynchronously, do not allow modules to keep things fully modular by defining stylesheets synchronously so that any subsequent use of custom tags by users can take effect without flickering, placeholders, etc:

const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute('src', 'module-specific-styling-without-flickering.css');
document.head.appendChild(link);

class CustomElementClass extends HTMLElement {...}
customElements.define('x-you-can-use-me-immediately-in-your-static-html', CustomElementClass);
export default CustomElementClass;

The same may be useful for JavaScript polyfills expressed as modules (or a series of interconnected modules) which the user may wish to import and use within the head of the document (without adding script tags for them non-modularly).

This isn't a bug in the current proposal, but some sort of new proposal. For that, see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md.