Js Delivr

Posted on  by admin
13th Mar 2019

The most newbie-friendly way to add a library to a project is to:

  1. jsDelivr is a public, open-source CDN (Content Delivery Network) developed by Dmitriy Akulov and Prospect One, focused on performance, reliability, and security.
  2. It is free to use for everyone, with no bandwidth limits.
  3. We are focused on production use, which also means we are very serious about security.
  4. All jsDelivr services support HTTPS.

This works, but it’s a painful process. It easier if you use CDNs like JSDelivr.

What is a CDN

CDN stands for content delivery network. Its main purpose is to let users download files faster. Read this article by Fastly if you’re wondering whether you should use a CDN.

CDNS let users download files faster by placing datacenters all over the world. When the browser sees a CDN link, they’ll serve up the library from the datacenter closest to the user. This is how CDNs work.

What is JSDelivr

JSDelivr is a special kind of CDN. It’s built to let users download JavaScript libraries that are hosted on npm and Github. (You can also load Wordpress plugins if they’re hosted on Wordpress.org).

If you use JSDelivr (or any other CDN that serves JavaScript libraries), you don’t need to copy-paste the source files into your project. You can use a link like this:

JSDelivr lets you specify the version of a library you want to download. If you want to specify a version, you add the version number after an @, like this:

How I use JSDelivr

I use JSDelivr more like a package manager since JSDelivr lets you specify the version of a library. I can upgrade or downgrade the library by changing a number. There’s no need to copy-paste the original source into my project.

However, I rarely use JSDelivr nowadays because I already have a build process that uses Webpack. Webpack lets you require libraries into frontend JavaScript. It lets you use npm as a package manager.

I only use JSDelivr for projects that:

  1. All jsDelivr related accounts are protected by strong passwords, 2FA, and IP whitelists where possible.
  2. Our critical code has been thoroughly reviewed both by us and several other independent experts.
  3. We also have protections in place to prevent people from using jsDelivr to serve malicious files, but if you find something that doesn't look right, report it at our issue tracker.

One example of such a project is the 20 components in Learn JavaScript.

Here’s why.

Students who’re enrolled in Learn JavaScript are trying to learn JavaScript. I don’t want to distract them by making them learn Webpack.

Instead, I want to help them focus on what they’re here for—learning JavaScript. I do this by removing complexity from projects we build together. I strip everything down to plain old HTML, CSS, and JavaScript.

How to use JSDelivr

We’ve talked about what is JSDelivr, why use it, and when to use it. Let’s dive into the details of using it now.

For the rest of the article, we’ll use a library called zl-fetch as an example.

Installing a library

To install a library, you need to add a