0

I am newbie to angular2, so far I know 2 ways of adding external css/js into app.

  1. Directly in index.html

    • Could be a CDN or local file.
  2. Installing the external npm package using the npm install <package-name>

    • Note: Works only if the package is available in NPM

I am trying to use an external js which is not available in NPM as of now. So, will be adding it in index.html

Now, this is a two part question.

  1. Does adding external links in index.html reduces the build time(anyway it's already super fast) in angular build --prod --aot?
  2. By using any of the two ways of adding external js/css files, will there be any performance impact in browser while using the app or it has no impact on performance?
4
  • Is it a node package? And maybe on GitHub? You could install it from Github. Using npm install https://github.com/<GITHUB_USER>/<GITHUB-PROJECT>/tarball/<BRANCH> Commented Apr 6, 2017 at 10:44
  • Also adding js to the index.html might help your general build-time and your package might be smaller, but it won't use any bundling. The ng-cli is doing this quite nicely and is also removing dead code. Commented Apr 6, 2017 at 10:46
  • Yes, it is available on Github. Commented Apr 6, 2017 at 12:17
  • This way you might be able to install it. I've two dependencies in my project, which are imported over GitHub. ...important is that the dependency has a package.json Commented Apr 6, 2017 at 12:45

1 Answer 1

1

Just to recap what I already said in the comments.

Adding the JS file into the index.html may reduce your build time, but it will exclude it from being watch by WebPack. WebPack is bundling you files and also removed dead code or sorts out duplicated dependencies. So there is a definite advantage of importing it as node package using the npm install

But sometimes this is just not possible. Then you need to add it to your index.html, but you won't have any advantage out of this.

If your package is not on npm but on GitHub then you can easily install it from GitHub. Here a small example using the jQuery repo:

npm install https://github.com/jquery/jquery/tarball/master --save

Important is that you use tarball instead of tree. This will install jQuery in you application.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.