Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add a 3rd party remote dependency? #2903

Closed
lfv89 opened this issue Oct 26, 2016 · 4 comments
Closed

How to add a 3rd party remote dependency? #2903

lfv89 opened this issue Oct 26, 2016 · 4 comments

Comments

@lfv89
Copy link

lfv89 commented Oct 26, 2016

Google's guideline for the "Google Sign" recommends this approach:

<script src="https://apis.google.com/js/platform.js" async defer></script>

I read in another issue though that when using an angular-cli project nothing should be directly added to the index.html, but adding a remote script in the angular-cli.json doesn't seems to work:

ERROR in multi scripts
Module not found: Error: Can't resolve '/Users/foo/Projects/bar/src/https:/apis.google.com/js/platform.js' in '/Users/foo/Projects/bar/node_modules/angular-cli/models'
 @ multi scripts

I already read the README.md but found nothing on this.

What is the recommended approach for this scenario?

Thank you.

@coryrylan
Copy link
Contributor

coryrylan commented Oct 26, 2016

I would think for this use case you would want the script directly in the index. Since the script is probably cache controlled by the host domain (Google) you would want the request to always come directly from their server. Ex: Google Analytics. If the code is called directly from your angular app that would be different and you would need to bundle it into the app.

@lfv89
Copy link
Author

lfv89 commented Oct 27, 2016

Facebook recommends this approach:

 (function(d, s, id){
     var js, fjs = d.getElementsByTagName(s)[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement(s); js.id = id;
     js.src = "//connect.facebook.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

Maybe angular-cli could accept a new remoteScripts field and also do this behind the scenes?

@filipesilva
Copy link
Contributor

For remote scripts it's perfectly fine to put whatever in index.html. Problematic tags are the ones that reference local files only.

That being, we have talked about allowing for a difference between dev/prod scripts, and them being loaded local/cdn. See #2796 regarding this topic.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants