Load external resources globally. Please use this with caution and as a last resort. Use conventions from project you are working on to load resources (ex: don't load AMD modules with this).
Index
Methods
-
<static> js(source, options) → {Promise.<DOMElement, Error>}
-
Load and execute an external JavaScript file.
Example
Asset.js("http://example.org/somejs.js") .then( function () { // Loaded }, function () { // Failure } );
Parameters
Name Type Description source
String the source URL of the JS file.
options
Object option hash
Properties
Name Type Argument Default Description force
Boolean <optional>
false by default, the file will be loaded only once. Passing
force: true
will force the file to be loaded again.timeout
Number <optional>
60000 a timeout in milliseconds
container
DOMElement <optional>
document.head where to put the created DOM element
Returns
a promise resolved with the script DOMElement or rejected with an Error.
- Type
- Promise.<DOMElement, Error>
-
<static> css(source, options) → {Promise.<StyleSheet, Error>}
-
Load and executed an external CSS file.
Example
Asset.css("http://example.org/somecss.css") .then( function () { // Loaded }, function () { // Failure } );
Parameters
Name Type Description source
String the source URL of the CSS file.
options
Object option hash
Properties
Name Type Argument Default Description force
Boolean <optional>
false by default, the file will be loaded only once. Passing
force: true
will force the file to be loaded again.timeout
Number <optional>
60000 a timeout in milliseconds
container
DOMElement <optional>
document.head where to put the created DOM element
Returns
a promise resolved with the DOM StyleSheet created or rejected with an Error.
- Type
- Promise.<StyleSheet, Error>