TemperStack
Intermediate8 min readUpdated Mar 18, 2026

How to enable CDN for better performance on DigitalOcean

Quick Answer

Enable DigitalOcean CDN by accessing Spaces CDN in your control panel, creating or selecting a Space, and configuring CDN settings with custom domain. This significantly improves global content delivery performance by caching static assets across multiple edge locations worldwide.

Prerequisites

  1. Active DigitalOcean account
  2. Existing Droplet or App Platform deployment
  3. Domain name configured
  4. Basic understanding of DNS settings
1

Access DigitalOcean Spaces

Log into your DigitalOcean control panel and navigate to ManageSpaces from the left sidebar. If you don't have an existing Space, click Create a Space to set up a new one. Select your preferred datacenter region and choose a unique name for your Space.
Tip
Choose a datacenter region closest to your primary audience for optimal performance
2

Enable CDN for your Space

In your Space dashboard, click on the Settings tab. Locate the CDN section and toggle the Enable CDN switch to the on position. DigitalOcean will automatically generate a CDN endpoint URL in the format spacename.region.cdn.digitaloceanspaces.com.
Tip
CDN enabling typically takes 5-10 minutes to propagate globally
3

Configure custom domain (optional)

To use a custom domain with your CDN, click Add Custom Domain in the CDN settings. Enter your subdomain (e.g., cdn.yourdomain.com) and click Add Domain. DigitalOcean will provide a CNAME record that you need to add to your DNS provider pointing to your CDN endpoint.
Tip
Use a subdomain like 'cdn' or 'static' to clearly identify cached content
4

Upload static assets

Upload your static files (images, CSS, JavaScript, videos) to your Space using the web interface, API, or s3cmd. Organize files in folders for better management. Set appropriate file permissions by selecting files and clicking Manage PermissionsPublic for publicly accessible content.
Tip
Compress images and minify CSS/JS files before uploading for better performance
5

Update application URLs

Modify your application code to reference static assets using your CDN URLs instead of local paths. Replace references like /images/logo.png with https://spacename.region.cdn.digitaloceanspaces.com/images/logo.png or your custom domain URL.
Tip
Use environment variables to easily switch between local and CDN URLs
6

Configure cache headers

Set appropriate cache headers for your files by selecting them in your Space and clicking Edit Metadata. Add Cache-Control headers like max-age=31536000 for static assets that rarely change, or shorter values for frequently updated content.
Tip
Use longer cache times for assets with versioned filenames
7

Test CDN performance

Verify your CDN is working by accessing your static assets through the CDN URL. Check response headers to confirm x-cache: HIT for cached content. Use tools like GTmetrix or Google PageSpeed Insights to measure performance improvements and ensure assets are loading from edge locations.
Tip
Test from different geographic locations to verify global CDN distribution

Troubleshooting

CDN not serving updated files
Clear the CDN cache by going to your Space settings, clicking Purge CDN Cache, and waiting 5-10 minutes for propagation. Consider implementing cache-busting with query parameters or versioned filenames.
Custom domain not working
Verify your CNAME record is correctly configured in your DNS provider pointing to the CDN endpoint. Use dig cdn.yourdomain.com to check DNS propagation, which can take up to 48 hours.
403 Forbidden errors on assets
Check file permissions in your Space. Select the files and set permissions to Public under Manage Permissions. Ensure your Space itself allows public read access in the settings.
Slow initial load times
Initial requests to uncached content will be slower. Implement cache warming by accessing your most important assets after upload. Consider using prefetch headers <link rel="prefetch" href="cdn-url"> for critical resources.

Related Guides

More DigitalOcean Tutorials

Other Tool Tutorials

Ready to get started with DigitalOcean?

Put this tutorial into practice. Visit DigitalOcean and follow the steps above.

Visit DigitalOcean