Now we can stop the deadly sin of committing our assets to git for Bower, CDNJS, and jsDelivr. Instead let’s use unpkg, a CDN for npm.

We typically think of npm as a package manager for node modules written in plain JS that will run without any compilation, but npm is actually built to support the publishing of compiled and packaged assets. This is useful for compiling CoffeeScript or transpiling ES2015. In fact, npm allows us to publish anything. So lets publish our client-side assets there too.

unpkg is a CDN that runs in front of npm. Any package published on npm is available through unpkg. Assets are accessed through URLs using this simple format:[email protected]/file. For example,[email protected]/lodash.min.js.

  1. Generate a UMD package using your favorite build tool.
  2. Add your packaged assets to .gitignore so it’s not commited to git.
  3. Add your packaged assets to the files array in package.json so they’re part of the package published to npm.

It’s simple and beautiful. unpkg is now my preferred CDN.