UUID generator · Guide

UUID v4 CDN: Loading a UUID Library in the Browser

Before browsers had a built-in generator, loading a UUID library from a CDN was standard. Today it is worth checking whether you need the library at all — and if you do, loading it safely.

You probably do not need it

Every current browser has a built-in generator, in secure contexts:

JavaScript
const id = crypto.randomUUID();   // no dependency, no network request

That covers v4 completely. A library is only needed for v5 name-based ids, v7 time-ordered ids, parsing and validation helpers, or support for a browser without randomUUID.

Loading it properly

If you do need the library, pin an exact version and add an integrity hash so a compromised or mutated file cannot execute:

HTML
<script src="https://cdn.jsdelivr.net/npm/uuid@11.0.3/dist/umd/uuid.min.js"
        integrity="sha384-..." crossorigin="anonymous"></script>
<script>const id = uuid.v4();</script>

Never use a floating tag such as @latest — a major release then changes your application without a deploy, and subresource integrity cannot be used at all because the file content is not fixed.

ES modules

For modern code, import directly rather than adding a global:

HTML
<script type="module">
  import { v4, v7 } from 'https://cdn.jsdelivr.net/npm/uuid@11.0.3/+esm';
  console.log(v4(), v7());
</script>

Note that subresource integrity does not cover a module's own imports, so a bundled build with a lockfile remains the stronger option for anything in production.

The trade-off

A CDN adds a third-party dependency on your critical path: a connection to another origin, a potential point of failure, and a party that sees your users' IP addresses.

For a value the browser can produce in microseconds, that is a poor trade. Bundle the library if you need it, and use the built-in when you do not.

Frequently asked questions

Do I still need a UUID library in the browser?

Only for v5, v7 or validation helpers. crypto.randomUUID covers v4.

Should I use @latest on a CDN?

No. Pin an exact version so releases cannot change your app, and so you can use an integrity hash.

Is a CDN safe for a UUID library?

With a pinned version and integrity hash, reasonably. Bundling is safer and removes the network dependency.

Ready to try it?

Open the free browser-based UUID generator and apply what you just read — no sign-up, runs locally.

Open the UUID generator tool