DEV Community

Cover image for Using JavaScript: as a package or as CDN
Vitor Norton for SuperViz

Posted on

Using JavaScript: as a package or as CDN

As a developer, you have two primary options when it comes to using JavaScript libraries or SDKs in your applications - through a npm or yarn installable module (or other package management tools) or a Content Delivery Network (CDN) via a <script> tag. Both methods have their unique advantages and usage scenarios.

Modern front-end development often uses as a module downloaded from npm due to the convenience it offers in managing project dependencies. If you're building a large-scale application with many dependencies, npm might be the way to go.

However, it's essential not to ignore the advantages of a CDN, it can significantly improve application load times and help giving quick hotfix, which can be particularly beneficial for smaller projects or quick prototypes.

Differences between CND and NPM

Let’s take a look at the differences between using npm and a CDN. Firstly, npm is a package manager for the JavaScript programming language.

When you install a JavaScript library or SDK via npm, you're downloading the package directly into your project. This method gives you the convenience of managing all your project dependencies in one place. It also allows you to use modern JavaScript tools like Webpack or Babel to bundle your applications and make better use of the import and export syntax.

On the other hand, using a CDN involves embedding a <script> tag into your HTML that points to the JavaScript file hosted on the CDN. This can be a quick and easy way to include a JavaScript library in a project without the need to manage dependencies or use build tools.

A significant advantage of using a CDN is that it can improve the loading time of your application. CDN servers are typically distributed globally, so the JavaScript file is downloaded from the server that is geographically closest to the user, reducing latency.

Additionally, if the user has already visited a site that uses the same CDN, like jQuery for example, the file might already be cached in their browser, further improving load times.

Remember to always consult the library or SDK's documentation for specific instructions on how to include it in your project, as the process can vary slightly depending on the package.

SuperViz Package

Both methods are fully supported and documented at SuperViz, and the choice between the two depends largely on your project needs and structure. Whether you're building a complex application with numerous dependencies or a simple prototype, SuperViz's can suit you with CND or a npm package.

If you are interested in finding detailed instructions on how to use our SDK as a CDN, like the technical differences from using it as a package, check our documentation page for this case before using SuperViz.

Top comments (0)