Overview
Cloudflare Workers Assets allows you to deploy static files alongside your Worker code. The asset management system handles uploading, caching, and serving static content with automatic optimization and CDN distribution.Assets are uploaded separately from your Worker bundle and can include HTML, CSS, JavaScript, images, and other static files up to 25 MiB per file.
Configuration
Basic Setup
Configure assets in yourwrangler.json file:
wrangler.json
Configuration Options
Path to the directory containing static assets. Can be relative to the config file or absolute.
Variable name to access assets from your Worker code. If omitted, assets are served directly without Worker involvement.
Controls how HTML files are served:
auto-trailing-slash- Automatically add trailing slashes to directory URLsforce-trailing-slash- Redirect all requests to include trailing slashesdrop-trailing-slash- Remove trailing slashes from URLsnone- Serve HTML files as-is
Behavior when a requested asset is not found:
single-page-application- Serveindex.htmlfor all 404s (SPA mode)404-page- Serve a custom 404.html pagenone- Return standard 404 response
Controls routing between Worker and assets:
true- All requests go to Worker first; use binding to fetch assetsfalse- Assets are served first; Worker handles non-asset routes- Array of patterns - Specific routes that should invoke Worker before assets
Asset Upload Process
The asset upload system uses an intelligent incremental upload mechanism:1. Manifest Generation
2. Incremental Upload
Only new or modified files are uploaded. The system:- Compares hashes with previously deployed assets
- Uploads only changed files
- Organizes uploads into buckets (max 50 MiB each)
- Uses concurrent uploads (3 buckets at a time)
- Implements exponential backoff on failures
3. Size Limits
Ignoring Files
Create a.assetsignore file in your asset directory to exclude files from upload:
.assetsignore
The ignore syntax follows
.gitignore patterns. Files matching these patterns won’t be uploaded to Cloudflare.Worker Integration
Assets Binding
Access assets from your Worker using the configured binding:src/index.ts
Custom Routing
Userun_worker_first with patterns for fine-grained control:
wrangler.json
/api/*,/admin/*,/auth/*routes invoke your Worker first- All other routes serve assets directly
- Worker can fall back to assets using the binding
Headers and Redirects
Add custom headers or redirects using special files: _headerspublic/_headers
public/_redirects
Command Line Usage
Deploy with Assets
Asset Information
During deployment, Wrangler displays upload progress:Best Practices
Optimize Assets
Compress images, minify CSS/JS, and use modern formats (WebP, Brotli) before uploading.
Cache Strategy
Use
_headers to set appropriate cache headers for different file types.Security
Never commit sensitive files. Use
.assetsignore to exclude .env and credential files.Smart Placement
Avoid using Smart Placement with
run_worker_first: true as it may increase latency for asset serving.Validation Rules
Error Handling
Common Errors
Asset directory does not exist_worker.js to .assetsignore or remove the file.
Advanced Examples
SPA with API Routes
wrangler.json
src/index.ts
Static Site with Custom 404
wrangler.json
public/404.html for custom error pages.