External Javascript files



I was wondering how to go about using external javascript sources in ember-cli? I am hoping to add the Google Maps API. I attempted to add it by including the following to the main index.html file like below:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

However I believe there is a better way. As it also produces errors from my script files stating that

'google' is not defined

whenever I run ember server



Yes, this is the correct way to load external javascript assets.

The errors you see are related to JSHint, as you are likely referencing a ‘google’ global, but have not let JSHint know that is ok.

You can either add google to the list of predefs in .jshintrc or you can add an inline comment in the specific file google is needed in.


{{content-for ‘head’}} is available for Ember CLI Addons, where you can inject script tags without pollutingindex.html. If you’re willing to move your external script dependency to an Addon, this is a nice alternative.

More info here: https://github.com/ember-cli/ember-cli/issues/1654