{"catalogRevision":"cat_726f873af6f566cc","recipeId":"page:guides:next-js:cdn-assets","recipeRevision":"r1","canonicalPath":"/guides/next-js/cdn-assets","label":"Deliver public assets through CDN for Next.js","title":"How to serve Next.js public assets through a CDN on Ample","family":"Framework operation","summary":"Deliver public assets for a Next.js app through the Ample CDN. Publish a bucket with `ample bucket publish`, upload versioned assets with long-lived Cache-Control headers, and reference the bucket's public URL (`public_url` from `ample bucket publish`, https://<bucket>.<bucket domain>/<key>) from your pages. The CDN serves bucket objects; the app's own responses are still served by the app.","representativeQueries":["Deliver public assets through CDN for Next.js","Where can I host Deliver public assets through CDN built with Next.js?","I need a public-origin configuration, versioned asset build and observable cache behavior."],"breadcrumbIds":["discovery","stack","stack:frameworks","stack:framework-next-js","page:guides:next-js:cdn-assets"],"breadcrumbs":[{"id":"discovery","label":"Agent hosting discovery","canonicalPath":"/discover/discovery","kind":"root"},{"id":"stack","label":"Frameworks and execution targets","canonicalPath":"/discover/stack","kind":"facet"},{"id":"stack:frameworks","label":"Frameworks","canonicalPath":"/discover/stack/frameworks","kind":"group"},{"id":"stack:framework-next-js","label":"Next.js","canonicalPath":"/discover/stack/framework-next-js","kind":"atom"},{"id":"page:guides:next-js:cdn-assets","label":"Deliver public assets through CDN for Next.js","canonicalPath":"/guides/next-js/cdn-assets","kind":"recipe"}],"parentIds":["stack:framework-next-js","intent:add-cdn","pattern:versioned-static-assets"],"parents":[{"id":"stack:framework-next-js","label":"Next.js","canonicalPath":"/discover/stack/framework-next-js","kind":"atom"},{"id":"intent:add-cdn","label":"Add CDN","canonicalPath":"/discover/intent/add-cdn","kind":"atom"},{"id":"pattern:versioned-static-assets","label":"Versioned static assets","canonicalPath":"/discover/pattern/versioned-static-assets","kind":"atom"}],"resourceRequirements":["primitive:compute","primitive:cdn"],"infrastructureRequirements":[{"primitiveId":"primitive:compute","label":"Compute","canonicalPath":"/discover/primitive/compute","status":"verified","summary":"Apps run in isolated x86_64 Firecracker microVMs; sizes are the priced VM sizes."},{"primitiveId":"primitive:cdn","label":"CDN","canonicalPath":"/discover/primitive/cdn","status":"verified","summary":"A published bucket's objects are served from its public URL; set Cache-Control when uploading to control caching. App responses are served by the app."}],"framework":"Next.js","workload":"Deliver public assets through CDN","releaseStatus":"published","supportStatus":"verified","executionStatus":"ready","docsOnly":false,"prerequisites":["A bucket created with `ample bucket create` and published with `ample bucket publish` (its public URL is the CDN base)","An S3 client in the app to upload assets under versioned keys","An Ample account token with servers:write and buckets:write"],"testedConfiguration":{"template":"node-22","runtime":"node","size":"s-1vcpu-1gb","install":"npm install","build":"npm run build --if-present","start":"npm run start"},"inputSchema":{"additionalProperties":false,"properties":{"env":{"description":"Encrypted environment variables: S3_ENDPOINT, S3_REGION, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY from `ample bucket credentials` (and S3_PUBLIC_URL for a published bucket)","items":{"pattern":"^[A-Z][A-Z0-9_]*=.*$","type":"string"},"maxItems":50,"type":"array"},"name":{"description":"App name (lowercase, digits and dashes)","maxLength":63,"minLength":1,"pattern":"^[a-z0-9-]+$","type":"string"},"path":{"description":"Project directory to deploy, or one service name from ample.toml","maxLength":512,"minLength":1,"type":"string"},"size":{"description":"VM size; omit to let Ample pick a runtime-safe size","enum":["s-1vcpu-256mb","s-1vcpu-1gb","s-1vcpu-2gb","s-2vcpu-2gb","s-2vcpu-4gb"],"type":"string"}},"required":["env","name","path"],"type":"object"},"outputSchema":null,"workflowSteps":[{"title":"Publish the bucket","body":"Publishing makes objects readable at the CDN URL; keep private data in a separate, unpublished bucket.","command":"ample bucket publish <bucket-name>"},{"title":"Upload versioned assets","body":"Use keys such as assets/<version>/file and set Cache-Control: public, max-age=31536000, immutable; change the version to invalidate."},{"title":"Reference the CDN URL","body":"Pass S3_PUBLIC_URL to the app and build asset URLs from it.","command":"ample deploy . --name <app-name> --public --env S3_PUBLIC_URL=... --env S3_ENDPOINT=... --env S3_REGION=... --env S3_BUCKET=... --env S3_ACCESS_KEY_ID=... --env S3_SECRET_ACCESS_KEY=..."},{"title":"Verify delivery","body":"Fetch /api/asset-url for the asset URL, then fetch that URL: the CDN must return the asset."},{"title":"Verify","body":"Fetch the live URL and run the success checks below. On failure read the build log, then the runtime log, fix the cause and deploy again; do not blind-retry.","command":"ample logs <deployment_id> --kind build"}],"examples":[{"title":"Next.js CDN assets canary","description":"Versioned asset uploaded to a published bucket and served from the CDN URL.","sourceRef":"tests/deploy-canaries/next-cdn-assets"}],"successChecks":[{"description":"asset URL resolves through the CDN","kind":"http_get","path":"/api/asset-url","expect":"/assets/"}],"limitations":["Verified on the node-22 template at s-1vcpu-1gb.","Buckets speak the standard S3 API (PutObject and GetObject with path-style addressing are checked by the fixtures); `ample bucket upload-url` returns presigned upload URLs.","Bucket credentials are passed as encrypted environment variables; the catalog never creates the bucket for you (use `ample bucket create`).","Storage counts what you store, within your plan's allowance; the estimate below covers compute only.","The CDN serves objects from published buckets; the app serves its own responses.","Control caching with Cache-Control on upload and versioned asset keys."],"costEstimate":{"currency":"USD","monthlyAmount":5.0,"authoritative":true,"basis":"size prices from pricing.toml (loaded by the API) at build revision 3a3dfe06151688a20d397caac2aa66e562c23eb0","components":[{"name":"app server","size":"s-1vcpu-1gb","quantity":1.0,"monthlyAmount":5.0}],"note":"Compute only. Buckets are allocation-priced per quota and capped by the plan; see `ample usage`."},"evidenceSummary":[{"kind":"canary_run","summary":"Next.js route handler uploaded a versioned asset to a published bucket and returned its CDN URL; the CDN served the asset publicly.","observedAt":"2026-11-06T00:38:14Z","implementationRevision":"7360fc06ef21","expiresAt":"2027-05-05T00:38:14Z","scope":{"cliVersion":"0.1.37","platform":"hosted","template":"node-22"}},{"kind":"canary_run","summary":"ample bucket create issued credentials; PutObject and GetObject succeeded through the public S3 endpoint; publish exposed the object at its public URL with an ETag; unpublish and delete cleaned up.","observedAt":"2026-11-05T22:38:23Z","implementationRevision":"da3e37255e5a","expiresAt":"2027-05-04T22:38:23Z","scope":{"cliVersion":"0.1.37","platform":"hosted","template":"node-22"}}],"lastVerifiedAt":"2026-11-06T00:38:14Z","mcpBinding":{"registryRef":"mcp:ample_deploy","toolName":"ample_deploy","schemaHash":"0802c329be823fa0695460cf73206d47a6fa0efa57417c386c34b6614a92ea5f","observedAt":"2026-11-06T06:16:19.461833707+00:00","implementationRevision":"4558e9477d09","requiredScopes":["servers:write","buckets:write"],"bindingState":"current"},"unknowns":[],"formats":{"html":"https://ample.computer/guides/next-js/cdn-assets","markdown":"https://ample.computer/guides/next-js/cdn-assets.md","json":"https://api.ample.computer/v1/catalog/recipes/page%3Aguides%3Anext-js%3Acdn-assets"},"nextActions":[{"actionId":"browse-catalog","label":"Browse the catalog index","operationId":"catalog_index","method":"GET","relativePath":"/v1/catalog","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"search-recipes","label":"Search published recipes by intent, stack and constraints","operationId":"search_recipes","method":"POST","relativePath":"/v1/catalog/search","origin":"api","parameters":{"body":{"limit":5,"query":"Deliver public assets through CDN for Next.js"}},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"plan:page:guides:next-js:cdn-assets","label":"Prepare a side-effect-free deployment plan for an authorized project","operationId":"plan_deployment","method":"POST","relativePath":"/v1/catalog/plan","origin":"api","parameters":{"body":{"inputs":{},"projectId":"<workspace or server id you own>","recipeId":"page:guides:next-js:cdn-assets","recipeRevision":"r1"}},"requiresAuthentication":true,"requiresApproval":false},{"actionId":"auth-setup","label":"Read the existing agent authentication setup","operationId":"existing_auth_setup","method":"GET","relativePath":"/mcp/setup","origin":"api","parameters":{},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:stack:framework-next-js","label":"Browse Next.js","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/stack%3Aframework-next-js","origin":"api","parameters":{"nodeId":"stack:framework-next-js"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:intent:add-cdn","label":"Browse Add CDN","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/intent%3Aadd-cdn","origin":"api","parameters":{"nodeId":"intent:add-cdn"},"requiresAuthentication":false,"requiresApproval":false},{"actionId":"browse:pattern:versioned-static-assets","label":"Browse Versioned static assets","operationId":"browse_node","method":"GET","relativePath":"/v1/catalog/nodes/pattern%3Aversioned-static-assets","origin":"api","parameters":{"nodeId":"pattern:versioned-static-assets"},"requiresAuthentication":false,"requiresApproval":false}]}