A micro-library (1.7kb) to lazy load and import Web Components.
- Synchronous module injection
- HTML Support
npm install lean-web-components
- inject(file) ⇒
string
- require(file) ⇒
DOMElement
string
**Kind**: global function
**Returns**: string
- - returns name of html file as a document create consumable name.
Param | Type | Description |
---|---|---|
file | string |
a http file path. |
Example
// injects file if needed and returns DOMNode <todo-widget></todo-widget>
var name = lean.inject('./widgets/todo-widget.html');
var todoWidget = document.createElement(name);
var anotherWayTodoWidget = document.createElement('todo-widget');
Kind: global function
Returns: DOMElement
- - HTML Imports return a createdDOM Element the import. This will execute the 'createdCallback' or 'created' function in the Web Component.
Param | Type | Description |
---|---|---|
file | string |
a http file path. |
Example
// injects file and returns DOMNode <todo-widget></todo-widget>
var todoWidget = lean.require('./widgets/todo-widget.html');
// won't inject file since injected above, and just create new element and require
var todoWidgetAgain = lean.require('./widgets/todo-widget.html');
- This module will only test evergreen browsers (latest versions).
- This project does not require
Polymer
, but does require Web Components to be enabled. Seewebcomponents-js
for a shim. - Dynamic names not support yet.
- Conditional builds: inject files based on any conditions, whether browser type or user event.
- Large Scale Ecosystem apps: Lazy load modules like widgets as you need them.
- Simple API
- Keep it small.
- Keep it fast.
- Work well with
stream-http
.
- Use simple injection techniques. (Simple script loads) [2] [3]
- Allow instant usage of web component if desired. [2] [1]
- Support only evergreen browsers [2] [3]
- Pass tests
- Hook into OSS devops services
- Add to bower
- Emit events on module loads for loading screen integration.
- Async stream loading