Tutorial6 min read·Updated

Django: WebP for Media Files and Static Assets

Django does not magically emit WebP. `STATIC` images should be converted before collectstatic. `MEDIA` uploads should be resized and encoded when saved so ImageKit/sorl are not chewing 8 MB originals.

static vs media

Static files are yours: convert the folder. Media files are users': validate, resize, encode WebP (or JPEG fallback) in a pre_save or celery task.

Why it matters

  • WhiteNoise/S3 will happily serve a 5 MB PNG forever.
  • Thumbnails generated from huge originals are slow.
  • Admin list thumbnails become painful.

How to do it

  1. Convert static/img to WebP.
  2. Update templates to .webp.
  3. For ImageField, max 2000 px and quality 80.

Settings that work

Same as other backends: 80% photos, 90% UI, cap width to layout.

Convert a batch in your browser. Nothing is uploaded.

Put it into practice

Convert your images to WebP right now, free and privately in your browser.

Open the converter

Frequently asked questions

Yes, if libwebp is installed. Alternatively call the Fast WebP API from Celery.

Modern browsers yes. The admin is just an img tag.

Keep reading

Tutorial6 min read

WebP in Laravel

Convert marketing assets to WebP locally, and convert user uploads with Intervention or the Fast WebP API.

Read more
Tutorial6 min read

WebP in Rails

Active Storage can produce WebP variants. Pre-convert marketing assets and set variant formats so production stays light.

Read more
Platforms6 min read

WebP for Drupal

Drupal's Image API can derive WebP styles, but source files are still your job. Bulk convert media to WebP and keep image styles simple.

Read more