Ember-Cli: 1.1.3.8 / Ember.Js >=2.0 Import Js-Libs into Pods/Components

36 Views Asked by At

Is there a way to include Javascript Libraries directly into Pods or Components without import in via app.import.

Explanation I want to use and Javascript-Library only in one Component, without the need to reference it in the global manner. Currently i have to include all Librarys about recommended Ember-Cli-Way with app.import, within the ember-cli-build.js.

But im eyes it is an Overhead, because i only need the functionality within my Pod, and not the entire application.

1

There are 1 best solutions below

0
Daniel On

You could store this library in public/ or vendor/ directories and then load it via AJAX request before you actually use it. This way you can avoid adding this library to vendor.js and loading it with each request each time.

For example, you could create util:

function getScriptCached(url) {
  return $.ajax({
    type: 'GET',
    url: url,
    dataType: 'script',
    cache: true
  });
};

And then use this function before initializing component:

getScriptCached('/js/chart.min.js');