Using CDN vs Installing library by NPM

CDN

Use CDN if you are developing a website that will be accessible by public internet users.

CDN Benefits:

  • Will be cached on most browsers because it’s used by a lot of other websites

  • Reduce the bandwidth

check for more benefits here

NPM

npm is a great tool to manage dependencies in your app using a module bundler.

Example:

assume using a webpack module bundler and jQuery is installed

import $ from 'jQuery'
...
var content = $('#id').html();

but the browser does not understand the import statement so you have to transpile the code with Webpack commands, the bundler will check all the used dependencies and bind them in a single file without any dependencies problems.

Useful links: Getting started with webpack

Leave a Comment