https://github.com/theprofs/defer-script
Load deferred scripts that survive vulcanisation/bundling in Polymer 1.x
https://github.com/theprofs/defer-script
asset-loading polymer web-components
Last synced: 15 days ago
JSON representation
Load deferred scripts that survive vulcanisation/bundling in Polymer 1.x
- Host: GitHub
- URL: https://github.com/theprofs/defer-script
- Owner: TheProfs
- License: mit
- Created: 2018-01-13T17:58:12.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-01-15T08:44:23.000Z (almost 8 years ago)
- Last Synced: 2025-02-14T12:48:22.452Z (11 months ago)
- Topics: asset-loading, polymer, web-components
- Language: HTML
- Homepage:
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# \
[](https://travis-ci.org/TheProfs/defer-script)
Load deferred scripts that survive vulcanisation/bundling.
## Usage
```bash
$ bower install --save defer-script
```
### Basic
In the below example, `testLib` will be loaded *after* the element is attached,
regardless if this element was vulcanised/bundled.
In short, the `src` is not included in any bundles.
```html
```
**Important:** All non-`http`/`https` scripts are passed through
[`this.resolveUrl()`][resolve-url] to resolve their relative path.
### Multiple scripts
You can provide multiple `src`'s by separating them with a comma.
```html
```
### Checking load status
When all `src`s have loaded successfully, a `loaded` attribute will be added
to the element.
```html
```
The element will also fire `load`/`error` events where appropriate:
```javascript
// Success, all srcs have loaded
document.querySelector('defer-script').addEventListener('load', () => {
console.log('loaded')
})
// Error, at least 1 src has failed to load
document.querySelector('defer-script').addEventListener('error', e => {
console.error(e.detail)
})
```
## Tests
```
$ polymer test
```
## Authors
- [The Profs][the-profs]
## License
MIT License
[resolve-url]: https://www.polymer-project.org/1.0/docs/api/Polymer.Base#method-resolveUrl
[the-profs]: https://github.com/TheProfs