DevOps45-75 min
CDN Setup and Asset Distribution
Put hashed assets behind a CDN, keep HTML fresh, compress text responses, and verify edge cache behavior.
CloudflareCloudFrontVercelNginx
Prerequisites
- A deployed frontend or static asset bucket.
- DNS access or hosting provider CDN settings.
- A build that fingerprints static assets.
1
Plan the implementation
Start by choosing the exact page, route, API, or deployment surface you want to improve. A narrow target makes the implementation measurable and easier to verify.
- Write down the current behavior and the user-facing problem it creates.
- Pick one measurable success signal such as bundle size, latency, error rate, security coverage, or UI responsiveness.
- Identify the files, routes, providers, and environment variables involved.
- Create a rollback note before changing production-sensitive configuration.
2
Set up the required tools
Install or configure only the tools needed for this implementation. Keep config close to the feature so future developers can find the moving parts quickly.
Implementation snippet
curl -I https://cdn.example.com/assets/app.jsChecklist
- Dependencies are added to the correct workspace package.
- Environment variables are documented in `.env.example` when needed.
- Local development still starts without production-only secrets.
- The change is small enough to review in one pull request.
3
Implement the core pattern
- Confirm static assets include content hashes in filenames.
- Route `/assets` or the static build directory through the CDN.
- Set long immutable caching for hashed assets.
- Keep HTML and API responses on shorter caching rules.
- Verify `cf-cache-status`, `x-cache`, or equivalent edge cache headers.
Implementation snippet
# Example Nginx asset cache
location /assets/ {
add_header Cache-Control "public, max-age=31536000, immutable";
gzip_static on;
try_files $uri =404;
}4
Handle edge cases
Checklist
- Asset URLs are cacheable for repeat visits.
- HTML updates are not trapped behind long CDN cache.
- Brotli or gzip compression is enabled for text assets.
- A cache purge or versioned deployment path exists for emergencies.
5
Verify before production
- Run the app locally and test the normal success path.
- Test one failure path, one empty state, and one slow-network or retry path.
- Run the project build and any related unit or integration tests.
- Check browser console, server logs, and network responses for hidden warnings.
- Document the final behavior, commands used, and any follow-up work.