UNPKG
unpkg is a fast, global content delivery network for everything on npm. Use it to quickly and easily load any file from any package using a URL like:
unpkg.com/:package@:version/:file
Package Indexes
Append a /
at the end of a URL to view a listing of all the files in a package root or subdirectory.
Package Metadata
You can get metadata about the files in any npm package by appending ?meta
to any root package URL or subdirectory URL.
For example:
Cache Performance
unpkg runs entirely on Cloudflare's global edge network using Cloudflare Workers. This allows unpkg to scale to serve billions of requests every day with low latency from hundreds of locations worldwide. In addition, the "serverless" architecture of Cloudflare Workers allows unpkg to scale immediately to satisfy sudden spikes in traffic.
Files are cached based on their permanent URL, which includes the npm package version. This works because npm does not allow package authors to overwrite a package that has already been published with a different one at the same version number.
URLs that do not specify a fully resolved package version number redirect to one that does. This is the latest
version when none is specified, or the maximum satisfying version when a semver range is given. For the best chance of getting a cache hit, use the full package version number in your unpkg URLs instead of an npm tag or semver range.
Workflow
For npm package authors, unpkg relieves the burden of publishing your code to a CDN in addition to the npm registry. All you need to do is include your UMD build in your npm package (not your repo, that's different!).
You can do this easily using the following setup:
- Add the umd (or dist) directory to your .gitignore file
- Add the umd directory to your files array in package.json
- Use a build script to generate your UMD build in the umd directory when you publish
That's it! Now when you npm publish you'll have a version available on unpkg as well.
About
unpkg is an open source project from @mjackson. unpkg is not affiliated with or supported by npm in any way. Please do not contact npm for help with unpkg. Instead, please reach out to @unpkg with any questions or concerns.