collectstatic · STATIC_ROOT · Local

Optimize Django Static Images — Before collectstatic Copies Them

Compress the images in your app static/ folders and STATICFILES_DIRS before you deploy. collectstatic and WhiteNoise move files around, but neither makes them smaller.

Quick answer

collectstatic gathers the images from your apps' static/ directories into STATIC_ROOT without re-encoding them, and manifest storage only adds a hash to the filename. So the file you commit is the file your visitors download. Compress your static images with TinyPixels before you run collectstatic.

How to compress images before collectstatic

1

Download and open TinyPixels

Free to install on Mac or Windows — no account needed to start.

2

Resize template art to its display size

Hero images and card graphics are often saved much larger than the template shows them.

3

Compress the folders

Drop them into TinyPixels. Convert big hero images to WebP if you update the {% static %} references.

4

Commit, then run collectstatic

The smaller files are copied into STATIC_ROOT and hashed as usual.

What collectstatic and WhiteNoise do with images

Django's static files flow is a copy operation. collectstatic walks each installed app's static/ directory plus any STATICFILES_DIRS entries and copies the files into STATIC_ROOT, where your web server or a middleware serves them. Nothing in that path touches the pixels.

ManifestStaticFilesStorage, and WhiteNoise's CompressedManifestStaticFilesStorage built on top of it, add a content hash to each filename so browsers can cache aggressively. WhiteNoise also pre-compresses text files with gzip or Brotli, but it skips formats like JPEG, PNG and WebP by default, because they are already compressed. A big PNG stays a big PNG.

User uploads are a different problem. Files in MEDIA_ROOT arrive at runtime, so a pre-commit pass cannot reach them; they need handling in your application code. This page is about the images you ship with the code: logos, hero art, illustrations and template graphics.

Source folders, not STATIC_ROOT

Compress what you commit. STATIC_ROOT is rebuilt on every deploy.

Works with any storage backend

Plain, Manifest or WhiteNoise storage all serve the bytes they are given.

No deploy-time package

Nothing to install in requirements.txt or run during release.

Format conversion

Convert hero images to WebP and update the template references.

Where images sit in a Django project

LocationWhat happensYour move
App static/ directories and STATICFILES_DIRScollectstatic copies them into STATIC_ROOT unchanged.Compress before commit
ManifestStaticFilesStorageAdds a content hash to the filename. No re-encoding.Nothing extra after compressing
WhiteNoise compressionGzip or Brotli for text assets; images are skipped by default.Do not rely on it for images
MEDIA_ROOT uploadsArrive at runtime from users, outside the repo.Handle in application code if needed
Django admin and third-party app assetsShipped with the package and already optimized.Leave them

Storage classes and settings vary by Django version and deployment setup, so confirm which one your project uses.

Common mistakes with Django static images

Compressing STATIC_ROOT

The folder is regenerated by every collectstatic run, so changes there disappear. Compress the sources in your repository.

Expecting WhiteNoise to shrink images

Its compression targets text files. JPEGs and PNGs pass through at full size.

Mixing up static and media

Static files ship with your code and can be compressed ahead of time. Media files are uploaded later and need a runtime solution.

Renaming files without updating {% static %} tags

With manifest storage and DEBUG off, a reference to a file that doesn't exist raises a missing manifest entry error. Search your templates for the old filename after converting.

Frequently asked questions

Does collectstatic compress images?

No. It copies files from your static directories into STATIC_ROOT as they are. Compress the images before running it.

Does WhiteNoise compress images?

Not by default. WhiteNoise pre-compresses text assets, and it skips already-compressed image formats.

What about images users upload to MEDIA_ROOT?

Those arrive after deployment, so a pre-commit pass can't reach them. Resize or recompress them in your application code if you need to. TinyPixels handles the images you ship with your code.

Which folder should I compress, STATICFILES_DIRS or STATIC_ROOT?

The source folders: your apps' static/ directories and STATICFILES_DIRS. STATIC_ROOT is generated output and gets overwritten.

Can I batch compress all my Django static images at once?

Yes. Drop the static folders into TinyPixels and every image compresses in one local pass.

Slim down your Django static files

Free to start. No credit card, no account, no cloud. See Pro pricing →