Skip to content Skip to sidebar Skip to footer

Angular 2: Why To Use Npm Manager Instead Of Cdn References?

Angular 2 looks better and simpler than Angular, however, I have a problem using NPM - it is not allowed at my work. But the bigger question I have is why do we need NPM at all? I

Solution 1:

One of the benefits of Angular is that the framework is structured in a way that allows you to tailor the application bundle to your specific application needs.

This is not possible with a one size fits all iife download from a CDN

If you look at the Angular npm packages you will see that they consists of a number of smaller modules that make up the framework.

Using a technique called "Tree shaking" your bundler can run static analysis on your code dependencies and create a bundle that only includes referenced modules. This can drastically reduce the bundle size.

Here is a some more info about Tree Shaking:

http://www.syntaxsuccess.com/viewarticle/tree-shaking-in-javascript

Solution 2:

Mainly because a modern web app will use some kind of dependency or module loader, like requireJS or (in case of Angular2) SystemJS, or commonJS, and CDN sources make that more complicated, since it requires a new resource http connection to get your source asset, and from a different domain (crossserver scripting issues)

Post a Comment for "Angular 2: Why To Use Npm Manager Instead Of Cdn References?"