Django STATIC_URL and MEDIA_URL on a CDN

Take Django collectstatic and public media off WSGI workers with Cloud CDN, while admin and CSRF views stay on origin.

If STATIC_URL and MEDIA_URL still point at the same host that runs views, you are paying worker time for CSS. Point both at Cloud CDN and keep admin on Django.

collectstatic is an origin, not a product

Run collectstatic to a disk or host Cloud CDN can pull. Set STATIC_URL to the CDN hostname. ManifestStaticFilesStorage hashed names can live at the edge until the filename changes.

MEDIA_URL for public uploads

Public avatars, catalogue images and downloads belong on the CDN. Private media should stay signed at origin.

WhiteNoise can remain the origin-side static server. Cloud CDN caches that result worldwide.

Admin and CSRF

django-admin, login and any POST stay dynamic. Never cache HTML that embeds a per-user CSRF token.

DRF GET endpoints

Public identical GET JSON can be cached. Authenticated APIs must bypass. See the API caching guide.

Frequently Asked Questions

WhiteNoise can still serve as origin. Cloud CDN offloads the app cluster for global readers.

Use the storage hostname as origin, or sit Cloud CDN in front of the public URL.

Yes when it is anonymous and you can purge it. Most authenticated templates should bypass.

Put this on Cloud CDN.

Get started with our Management Console in less than 2 minutes, or connect with an expert to supercharge your business today.