UNPKG is a fast, global content delivery network for everything on npm . Use it to quickly and easily load any file on npm using a URL like:
unpkg.com/:pkg@:ver/:file
:pkg
is the name of the package on npm:ver
is the version of the package:file
is the path to a file in the package
For example:
- unpkg.com/preact@10.26.4/dist/preact.min.js
- unpkg.com/react@18.3.1/umd/react.production.min.js
- unpkg.com/three@0.174.0/build/three.module.min.js
You can also use any valid semver range or npm tag:
If you don't specify a version, the latest
tag is used by default.
Add a trailing /
to a directory URL to view a listing of all the files in that directory.
If you'd like to browse an older version of a package, include a version number in the URL.
If you don't specify a file path, UNPKG will resolve the file based on the package's default entry point. In older packages like jQuery, this will be the value of the main
field in the package.json
file.
In modern packages that use exports, UNPKG will resolve the file using the default
export condition.
So, for example if you publish a package with the following package.json
:
You would be able to load your package from UNPKG using a <script>
tag like:
The full exports
spec is supported, including subpaths. So if your package.json
looks like:
You can load the exp
subpath with:
Custom export conditions are supported via the ?conditions
query parameter. This allows you to load a different file based on the environment or other conditions. For example, to fetch React using the react-server
condition, you could do:
If you'd like to specify a custom build of your package that should be used as the default entry point on UNPKG, you can use either the unpkg
field in your package.json
or the unpkg
export condition in your exports
field.
Nobuild Apps
UNPKG is ideal for loading dependencies in apps that run entirely in the browser without a build step. You can load JavaScript modules from UNPKG directly in your HTML using an import map.
Below is a fully functional Preact app that does not require a build in order to run.
No bundler required! This is ideal for small projects, prototypes, or any situation where you'd like to get something up and running quickly without setting up a build pipeline.
Metadata API
UNPKG serves metadata about the files in a package when you append ?meta
to any package root or subdirectory URL.
For example:
This will return a JSON object with information about the files in that directory, including path, size, type, and subresource integrity value.
Cache Performance
UNPKG is a mirror of everything on npm. Every file on npm is automatically available on unpkg.com within minutes of being published.
Additionally, UNPKG runs on Cloudflare's global edge network using Cloudflare Workers, which allow UNPKG to serve billions of requests every day with low latency from hundreds of locations worldwide. The "serverless" nature of Cloudflare Workers also allows UNPKG to scale immediately to satisfy sudden spikes in traffic.
Files are cached on Cloudflare's global content-delivery network 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 and file path in your UNPKG URLs instead of an npm tag or semver range.
For example, a URL like unpkg.com/preact@10 will not be a direct cache hit because UNPKG needs to resolve the version 10
to the latest matching version of Preact published with that major, plus it needs to figure out which file to serve. So a short URL like this will always cause a redirect to the permanent URL for that resource. If you need to make sure you hit the cache, use a fixed version number and the full file path, like unpkg.com/preact@10.5.0/dist/preact.min.js.
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.