0

I have a simple question more about best practice/performance.

When you have to include a CSS or Javascript framework (bootstrap, jquery, ...) to your project, do you include them on the index.html or declare it on the .angular-cli.json?

I know that bouth aproaches work, but is there a best practice on this? Is there an advantage of using one or other?

Thanks for your comments.

1 Answer 1

1

The best approach is to install them using npm or yarn package managers and then add them to your .angular-cli.json

The advantage here is that you just have to look at one place to find all your dependencies, the package.json file. You can also easily upgrade to the latest version and the package manager will warn you if the version is not compatible with your other packages.

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

3 Comments

I agree. Additionally, concerning performance, if you are using a server that uses HTTP/1, the performance will be less than if you were to include them in angular-cli.json. This is because the number of calls to the server will increase if you include libraries in the HTML. If you use the angular-cli.json, they will be bundled in the scripts.bundle.js file: reducing calls. This does not matter with HTTP 2 though.
Thanks for your comments. Allow me another last question following @Dhyey answer. Is it better to: 1) install a framework, let's say Bootstrap, with npm as a project dependency or 2) to declare it using a CDN?
@jfpcarreria if u are using http 2 go for the cdn, if u r using http 1 go for npm

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.