2

I don't seem to understand the issue with serving static files in Python apps, for example Django. Now I am reading a documentation of WhiteNoise and first question is why it was developed in the first place? I mean what problem it solves? Why we can't save all the static files in /static folder and copy it to hosting.

a298b112
  • 83
  • 1
  • 8

1 Answers1

3

I don't seem to understand the issue with serving static files in Python apps, for example Django.

As is specified in the Django documentation on managing static files:

This method is grossly inefficient and probably insecure, so it is unsuitable for production.

Indeed, Django's views to serve static files are likely not very efficient. A webserver will typically cache a certain amount of files, use compression to send these to the browser (if the browser accepts this), etc. Django's views to serve static/media files are not designed to be competitive with a webserver like apache/nginx.

Even if that is solved, it using a signle server to serve static content is not a good idea. Often Content Delivery Networks (CDNs) are used to find a server close to the client that can serve these files.

The Django documentation therefore contains articles to deploy static files on a dedicated server and how to configure this server.

The whitenoise package is simply a best effort attempt to serve these files with a Python view. Python is more designed to reduce programmer time, not processing time, so while whitenoise is efficient, very likely it can not compete with CDN.

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555