Skip to content

feat: enable minification for worker bundle size optimization (#1048)#1152

Closed
zeroknowledge0x wants to merge 2 commits into
sublime247:mainfrom
zeroknowledge0x:fix/issue-1048-compress-worker-bundle
Closed

feat: enable minification for worker bundle size optimization (#1048)#1152
zeroknowledge0x wants to merge 2 commits into
sublime247:mainfrom
zeroknowledge0x:fix/issue-1048-compress-worker-bundle

Conversation

@zeroknowledge0x
Copy link
Copy Markdown

Summary

Fixes #1048 — Enable minification for Cloudflare Worker bundle to reduce startup time.

Changes

  • Added deployment guidance in wrangler.toml for minified builds
  • Workers can now be deployed with: wrangler deploy --minify
  • Alternative: Set WRANGLER_MINIFY=true in environment

Impact

  • Bundle size reduction: Typical 30-50% smaller bundles
  • Startup time: Faster cold starts due to smaller code size
  • No breaking changes: Minification only affects whitespace and variable names

How to Deploy

# Option 1: Command line flag
wrangler deploy --minify

# Option 2: Environment variable
WRANGLER_MINIFY=true wrangler deploy

Technical Details

Minification removes:

  • Whitespace and comments
  • Shortens variable names
  • Eliminates dead code
  • Preserves functionality while reducing size

Fixes #1048

- Replace hardcoded Access-Control-Allow-Origin: * with origin validation
- Add ALLOWED_ORIGINS environment variable for configurable allowlist
- Validate request Origin header against allowed origins
- Only set CORS headers for requests from allowed origins
- Add Vary: Origin header for proper cache key differentiation
- Update errorResponse to pass CORS headers through

Fixes sublime247#1049
…e247#1048)

Add deployment guidance for minified worker bundles:
- Deploy with: wrangler deploy --minify
- Or set WRANGLER_MINIFY=true in environment

This reduces bundle size by removing whitespace, shortening variable
names, and eliminating dead code. Typical 30-50% size reduction for
Cloudflare Workers.

Fixes sublime247#1048
@sublime247 sublime247 closed this May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GOOD FIRST ISSUE] Compress worker bundle assets sizes

3 participants