tc39 / proposal-dynamic-import

import() proposal for JavaScript
https://tc39.github.io/proposal-dynamic-import/
MIT License
1.87k stars 47 forks source link

Synchronous version? #58

Closed brettz9 closed 6 years ago

brettz9 commented 6 years ago

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).

domenic commented 6 years ago

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.