Which is best for using dependencies?: CDN VS Packages

Are you just starting out and you are not sure if you should be using CDN or npm packages in your projects?


Kuldeep Gupta

2 years ago | 2 min read

In this article, I am going to guide you on what is CDN, what are packages, and when to use what.

So, without wasting your time! Let's Get Started!

Table of Contents

1. What is CDN?

2. Benefits of CDN

3. What are packages?

4. Benefits of using packages

5. When to use what?

6. Conclusion

1. What is CDN?

А СDN or Content Delivery Network аllоws the quiсk trаnsfer оf data needed fоr lоаding Internet соntent inсluding HTML раges, jаvаsсriрt files, stylesheets, imаges, аnd videоs. The рорulаrity оf СDN serviсes соntinues tо grоw, аnd tоdаy the mаjоrity оf web trаffiс is served thrоugh СDNs, inсluding trаffiс frоm mаjоr sites like Fасebооk, Netflix, аnd Аmаzоn.

When CDNs were not introduced then putting the request for getting javascript files and stylesheets from other servers takes a lot of time which takes a lot of time of an end-user, to solve this problem and make web apps more optimized CDNs were introduced which solved this problem. As it creates a copy of data to the nearest server to an end-user and when the user requests for the same it doesn't take much time.

2. Benefits of using CDN

  • CDNs make serving libraries' request burden lower as compare to your own servers.
  • Most of the CDNs have servers all over the globe, so your own servers are not that much nearer to all other users.
  • CDNs are already properly configured which saves your time from the further configuration for static assets for your own servers.

3. What are packages?

What npm or Node Package Manager doc says -

A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry. For more information on creating a package.json file, see "Creating a package.json file".

Packages can be unscoped or scoped to a user or organization, and scoped packages can be private or public.

4. Benefits of packages

  • You have more control over data that is coming from a particular package.
  • You can simply import a particular function or feature and simply use it.

5. When to use what?

Even though CDNs are made to be reliable. It is a resource you have no control over. Maybe they will clean up the content after a while and remove (little used) resources. Maybe the CDN is blocked for the users. etc.

So, it depends:

  • how quickly can you adapt your program to resolve CDN-related issues.
  • are there network accessibility constraints?

Or, In simpler words, CDNs are good for testing projects but for professional projects using packages for installing dependencies is more preferable as it provides more control over data as compared to CDNs.

6. Conclusions

Before wrapping up I would suggest, if you are making some personal projects then the use of CDN is good as it offers you fast fetching of data and it loads quite fast as compared to packages but if you are working on some projects which will be used by several other users, then, I will suggest you should avoid using CDN because it is not that much stable as the packages.

Thank you for reading!


Created by

Kuldeep Gupta

A budding full stack developer and a graphic designer, always ready to learn and improve skills. React Lover!







Related Articles