page:guides:next js:cdn assets

Deliver public assets through CDN for Next.js

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 CDN URL (https://cdn.//) from your pages. The CDN serves bucket objects; the app's own responses are still served by the app.

Resources Required

Prerequisites

Workflow Steps

  1. Publish the bucket: Publishing makes objects readable at the CDN URL; keep private data in a separate, unpublished bucket.
    • Command: ample bucket publish
  2. Upload versioned assets: Use keys such as assets//file and set Cache-Control: public, max-age=31536000, immutable; change the version to invalidate.
  3. Reference the CDN URL: 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=...
  4. Verify delivery: Fetch /api/asset-url for the asset URL, then fetch that URL: the CDN must return the asset.
  5. Verify: 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 [YOUR_LOG_OPTIONS]

Limitations

Cost Estimate

Examples

Success Checks

Next Actions