Safeguard
Developer Tools•

How do edge size limits shape which dependencies you can use?

Edge platforms cap bundle size at 10 KB, 1 to 4 MB gzipped, or 64 MiB uncompressed. See how each limit pushes you toward fewer dependencies.

Safeguard Security Team
4 min read

Edge bundle limits force dependency discipline. CloudFront Functions allow 10 KB of code and libraries, Vercel's Edge runtime allows 1 to 4 MB after gzip depending on plan, and Cloudflare Workers allow 64 MiB uncompressed. The smaller the ceiling, the fewer third-party packages you can carry and the less there is to patch.

The limits, as documented

PlatformDocumented limit
CloudFront Functions10 KB for function code and included libraries
Lambda@Edge50 MB for code and libraries (viewer and origin events)
Vercel Edge runtime1 MB Hobby, 2 MB Pro, 4 MB Enterprise, after gzip
Cloudflare Workers64 MiB uncompressed, with no compressed size limit

Limits change, so check the current pages before you design around a number.

Size is also a startup problem

Cloudflare documents that a Worker must parse and execute its global scope within 1 second, and that larger bundles and expensive initialization in global scope increase startup time. It lists reducing size as: remove unnecessary dependencies, move config, static assets and binary data to storage, and split work across Workers with service bindings.

That matches what builders find in practice. A heavy dependency costs bytes, then startup time, and then review effort.

The security angle on a smaller bundle

Every package in a bundle is code you did not write and must keep patched. Fewer packages means:

  • A smaller list of advisories to watch
  • A shorter path from a fix release to a deploy
  • Less code to read when something goes wrong

There is a trade. A tiny replacement you write yourself carries its own bugs, and security-sensitive code such as signature checks and token parsing is a poor candidate for a rewrite. Use a maintained library there, and remove the convenience packages instead.

A trimming routine

  1. Measure first. On Cloudflare, AWS-style tools and Vercel builds all report bundle size. Cloudflare documents that a dry run shows Total Upload, which is the uncompressed size that counts toward the limit.
  2. List the five biggest contributors. Use your bundler's analysis output.
  3. Ask what each one does for the route. If the answer is one function, import only that function or write it.
  4. Remove dev-only code from the production path. Wrangler, for example, statically replaces the NODE_ENV value at build time, so development-only code can be removed from the production bundle.
  5. Re-measure and record the new size in the repo so growth is visible.

What not to do

Do not hit a limit by hiding code outside the bundle without review. Pulling a library from a remote URL at run time, or lazy loading files you never scan, makes the size problem go away and the supply chain problem worse. Anything the function can execute should be in the inventory and in your scan.

Try it yourself

Open the dependency inventory demo and sort by package. The goal is the same as a size trim: find the entries that appear once and do little.

Click through it at your own pace, or open it full screen.

Where Safeguard fits

Safeguard's SBOM and dependency scanning list what actually ships in each build, including transitive packages that inflate a bundle without being obvious. Use that list to decide what to cut. A free scan is at gold.safeguard.sh/scan.

Quick check

Does gzip help me stay under the Cloudflare Workers limit?

Cloudflare documents that only the uncompressed bundle size counts toward the 64 MiB limit, and there is no compressed size limit.

Is the smallest bundle always the safest?

No. Rewriting security-sensitive code yourself can add bugs. Trim convenience packages first and keep maintained libraries for crypto and token handling.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.