An EmberJS add-on for dynamically loading scripts
- Ember.js v4.8 or above
- Ember CLI v4.8 or above
- Node.js v18 or above
ember install ember-cli-script
First, inject the script
service into the corresponding EmberJS entity. Then,
call the script.load(src)
method. If the script has not been loaded into the
document, then it will be loaded. If it has been loaded, then the currently loaded
script is used.
import { inject as service } from '@ember/service';
export default SomeService extends Service {
@service
script;
constructor () {
super (...arguments);
this.script.load ('https://cdn.somescript.com').then (script => {
// The script has been loaded. We can now use it contents.
});
}
}
This add-on is intended to be used within applications and add-ons that need
to control when and how a script is dynamically loaded. It is an alternative
to using the <script>
tag.
<script src="https://cdn.somescript.com" async defer />
See the Contributing guide for details.
This project is licensed under the MIT License.