DjangoWhiteNoise Reference

The DjangoWhiteNoise class takes all the same configuration options as the WhiteNoise base class, but rather than accepting keyword arguments to its constructor it uses Django settings. The setting names are just the keyword arguments uppercased with a ‘WHITENOISE_’ prefix.

Available Settings

WHITENOISE_ROOT
Default:None

Absolute path to a directory of files which will be served at the root of your application (ignored if not set).

Don’t use this for the bulk of your static files because you won’t benefit from cache versioning, but it can be convenient for files like robots.txt, favicon.ico, or Google Site Verification files which you want to serve at a specific URL.

WHITENOISE_MAX_AGE
Default:60

Time (in seconds) for which browsers and proxies should cache non-versioned files.

Versioned files (i.e. files which have been given a unique name like base.a4ef2389.css by including a hash of their contents in the name) are detected automatically and set to be cached forever.

The default is chosen to be short enough not to cause problems with stale versions but long enough that, if you’re running WhiteNoise behind a CND, the CDN will still take the majority of the strain during times of heavy load.

WHITENOISE_CHARSET
Default:settings.FILE_CHARSET (utf-8)

Charset to add as part of the Content-Type header for all files whose mimetype allows a charset.

WHITENOISE_ALLOW_ALL_ORIGINS
Default:True

Toggles whether to send an Access-Control-Allow-Origin: * header for all static files.

This allows cross-origin requests for static files which means your static files will continue to work as expected even if they are served via a CDN and therefore on a different domain. Without this your static files will mostly work, but you may have problems with fonts loading in Firefox, or accessing images in canvas elements, or other mysterious things.

The W3C explicity state that this behaviour is safe for publicly accessible files.

WHITENOISE_GZIP_EXCLUDE_EXTENSIONS
Default:('jpg', 'jpeg', 'png', 'gif', 'webp','zip', 'gz', 'tgz', 'bz2', 'tbz', 'swf', 'flv')

File extensions to skip when gzipping.

Because the gzip process will only create compressed files where this results in an actual size saving, it would be safe to leave this list empty and attempt to gzip all files. However, for files which we’re confident won’t benefit from compression, it speeds up the process if we just skip over them.