Hosting a static site on DigitalOcean Spaces with built‑in CDN
Learn how to host a static website on DigitalOcean Spaces, enable the built‑in CDN, and verify delivery with simple doctl commands and curl checks.
12 Oct 2025, 21:09 UTC

Problem: cheap, maintenance‑free static asset hosting
You need to serve a small static website or single‑page app without managing a web server, but you also want low latency for visitors worldwide. DigitalOcean Spaces offers object storage with an optional CDN edge cache that can be turned on with a single toggle.
Takeaway
By creating a public Space, enabling the CDN, and uploading your site with doctl, you get a globally cached endpoint at no extra server cost. The trade‑off is that all objects become publicly readable and dynamic server‑side processing isn’t available.
1. Create a Space and make it public
First, ensure you have doctl installed and authenticated with a token that has read and write scope for Spaces.
# Run locally on your workstation
# Replace MY_TOKEN with your DigitalOcean API token (keep it secret)
doctl auth init --access-token MY_TOKEN
Create a new bucket (Space) in the region closest to your primary audience. The example uses nyc3.
doctl spaces create my-static-site --region nyc3By default a Space is private. Make it public so anyone can read objects:
doctl spaces update my-static-site --publicRisk: Once public, every object in the bucket is accessible via its URL. Do not store secrets or sensitive data here.
2. Enable the built‑in CDN
Spaces includes an optional edge cache. Enabling it creates a CDN URL that points to the same objects but serves them from nearby edge locations.
doctl spaces cdn enable my-static-siteThe command returns a CDN endpoint like
my-static-site.nyc3.cdn.digitaloceanspaces.com. This endpoint automatically caches GET responses; you can purge individual objects later if needed.3. Upload your static site
Assuming your site files are in a local folder
./sitecontaining anindex.htmland assets:# Upload recursively, preserving directory structure doctl spaces upload my-static-site ./site --recursiveVerify the upload succeeded by checking the object list:
doctl spaces list my-static-site4. Verify the CDN is working
Request the root document via the CDN URL and inspect response headers to confirm caching.
curl -I https://my-static-site.nyc3.cdn.digitaloceanspaces.com/index.htmlLook for headers such as:
Age:seconds the object has been in the cacheVia:indicates the request passed through an edge nodeCache-Control:as set by Spaces (defaultpublic, max-age=3600)
If you see a non‑zero Age and a Via header, the CDN is serving a cached copy.
Limitations and practical checks
- No server‑side processing: Spaces cannot run scripts; you need a separate backend for dynamic features.
- CDN region coverage: Edge locations are available in a subset of regions (e.g., NYC, SFO, AMS, SGN). Verify latency from your target users with tools like
pingorcurl -w "%{time_total}". - Public exposure: Double‑check that no sensitive files were uploaded before making the bucket public.
To confirm your site is reachable via the CDN, open the URL in a browser or run:
curl -s -o /dev/null -w "%{http_code}" https://my-static-site.nyc3.cdn.digitaloceanspaces.com/Expect a
200response. If you receive403or404, re‑check the public flag and that the object exists in the bucket.Closing
DigitalOcean Spaces gives you a low‑cost, zero‑maintenance way to host static assets, and the one‑click CDN option adds global caching without extra configuration. Keep the bucket public only for intended assets, monitor cache headers, and remember that dynamic logic must live elsewhere.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.