What’s the point of Django’s collectstatic?

Collect static files from multiple apps into a single path

Well, a single Django project may use several apps, so while there you only have one myapp, it may actually be myapp1, myapp2, etc

By copying them from inside the individual apps into a single folder, you can point your frontend web server (e.g. nginx) to that single folder STATIC_ROOT and serve static files from a single location, rather than configure your web server to serve static files from multiple paths.

Persistent URLs with ManifestStaticFilesStorage

A note about the MD5 hash being appended to the filename for versioning: It’s not part of the default behavior of collectstatic, as settings.STATICFILES_STORAGE defaults to StaticFilesStorage (which doesn’t do that)

The MD5 hash will kick in e.g. if you set it to use ManifestStaticFilesStorage, which adds that behavior.

The purpose of this storage is to keep serving the old files in case
some pages still refer to those files, e.g. because they are cached by
you or a 3rd party proxy server. Additionally, it’s very helpful if
you want to apply far future Expires headers to the deployed files to
speed up the load time for subsequent page visits.

Leave a Comment