Topic · Files & assets

Static files & frontend builds for Django in production

collectstatic, WhiteNoise, CDNs, cache busting, and bundlers like Vite and Tailwind in production.

from source files to cached URLsApp static/CSS, JS, imagescollectstaticevery releaseSTATIC_ROOTapp.3f9c.cssNginx or CDNor WhiteNoiseBrowsercached a yearHashed names are what make aggressive caching safe

Static files are your CSS, JavaScript, and images, collected on every release and served by Nginx, WhiteNoise, or a CDN. With hashed names they can be cached forever.

The guides cover serving them correctly, frontend builds with Vite or Tailwind, cache busting, and the errors that turn them into 404s, 403s, or unstyled pages.

11Set it up
3Run it well
1Check it
12Fix it

Set it up

Guides that take this from nothing to running in production.

  • Django Static vs Media Files in Production

    Many Django deployments break because static files and media files are treated as the same thing.

  • How to Serve Django Static Files with WhiteNoise

    Django does not safely serve static files in production by default. With DEBUG=False, you still need a production path for CSS, JavaScript, fonts, and images collected from your...

  • Serve Django Static Files Through CloudFront

    Serve Django static files from CloudFront: S3 with origin access control or origin pull, hashed filenames, immutable caching, and CORS.

  • Deploy Django with Vite Frontend Assets

    Ship Vite-built JavaScript and CSS with Django in production: manifest-based asset tags with django-vite, a Node build stage, collectstatic, cache headers, and avoiding dev-server leaks.

  • Build Tailwind CSS for Django in Production

    Build a minified Tailwind CSS file for Django releases: scanning templates and Python code, the standalone CLI without Node, Docker build stages, collectstatic hashing, and missing-class bugs.

  • Compile Django Translations During Deployment

    Ship Django translations reliably: run compilemessages in CI or a Docker build stage with gettext, ignore virtualenvs, validate .po files, restart workers, and verify every language in production.

  • WhiteNoise vs Nginx for Django Static Files

    Compare serving Django static files with WhiteNoise inside the app versus Nginx or a CDN: setup, compression and cache headers, performance, containers and PaaS, media files, and the setup that suits each deployment.

  • Serve Django Static and Media Files Through Bunny CDN

    Put Bunny CDN in front of a Django site: create a pull zone for WhiteNoise static files or an object storage origin, use hashed file names with long cache headers, serve media from Bunny Storage with django-storages, and purge or sign URLs when needed.

  • Serve a Django Site Through Fastly

    Put Fastly in front of Django: configure the origin and host header, cache anonymous pages with Surrogate-Control and surrogate keys, bypass logged-in users, purge by key from Django signals, and set shielding, TLS, and compression for static files.

  • Serve Django and a React SPA on the Same Domain

    Serve a React SPA and a Django API from one domain with Nginx: routing fallback, API proxying, cache headers, and CSRF-safe session auth.

  • Serve Django Static Files on Kubernetes

    Choose how to serve Django static files on Kubernetes: WhiteNoise inside the app image, an Nginx sidecar sharing an emptyDir, a separate static image, or object storage with a CDN, and avoid shared volumes, stale files, and collectstatic at pod start.

Run it well

Tuning, reliability, and operations once it works.

  • Long-Lived Caching for Django Static Files

    Cache Django static files for a year without stale assets: manifest hashing, immutable Cache-Control headers in Nginx and WhiteNoise, CDNs, and deploy order.

  • Speed Up Django collectstatic to S3

    Make collectstatic to S3 or other object storage fast: skip unchanged files, use storage backends that compare hashes, collect locally then sync with the AWS CLI, skip post-processing where safe, and run it once per release in CI instead of on every server.

  • Purge the Cloudflare or CDN Cache After a Django Deploy

    Decide what to purge from Cloudflare or another CDN after deploying Django: rely on hashed static file names, purge cached HTML by URL or tag, automate purges from CI with an API token, avoid purge-everything, and keep old assets available during rollouts.

Check it

Review lists to run before launch or after a change.

  • Django Static Files Production Checklist

    A production checklist for Django static files: STATIC_ROOT and collectstatic in the build, manifest storage for cache busting, serving with WhiteNoise, Nginx, or a CDN, cache headers, compression, frontend bundles, and admin assets.

Fix it

Errors and symptoms, each traced to a cause and a fix.

Learning paths through this topic

Related topics