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
| Platform | Documented limit |
|---|---|
| CloudFront Functions | 10 KB for function code and included libraries |
| Lambda@Edge | 50 MB for code and libraries (viewer and origin events) |
| Vercel Edge runtime | 1 MB Hobby, 2 MB Pro, 4 MB Enterprise, after gzip |
| Cloudflare Workers | 64 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
- 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.
- List the five biggest contributors. Use your bundler's analysis output.
- Ask what each one does for the route. If the answer is one function, import only that function or write it.
- 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.
- 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
- Differences between CloudFront Functions and Lambda@Edge, AWS documentation
- Edge Runtime, Vercel documentation
- Limits, Cloudflare Workers documentation
- Bundling, Cloudflare Workers documentation
Last reviewed: 19 October 2026.