0

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.

Marcus
  • 65
  • 7
  • This is all wrong. Import it properly with broccoli then use an ES 6 import statement within your component or whatever is is you want to use the library with. Don't do what commenter below says. Why would you Ajax in a library that you could just build into your project?? Madness. – Christopher Milne Aug 21 '15 at 22:31
  • Ty, do you have an example for me ? :). – Marcus Aug 22 '15 at 13:35
  • Here you go http://blog.abuiles.com/blog/2014/10/17/working-with-javascript-plugins-in-ember-cli-part-2/ – Christopher Milne Aug 22 '15 at 13:46
  • Thank you Milne :), could you post your comment as Anwer, than i would accept this as solution..? :D And perfect, at the moment i read Ember-Cli Book ;). – Marcus Aug 22 '15 at 13:54

1 Answers1

0

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');
Daniel Kmak
  • 18,164
  • 7
  • 66
  • 89