From the Django on mod_wsgi page:
We recommend using a separate Web server – i.e., one that’s not also running Django – for serving media.
Why?
Django also provides a mechanism for collecting static files into one place so that they can be served easily. Using the collectstatic command, Django looks for all static files in your apps and collects them wherever you told it to, i.e. the STATIC_ROOT .
Configuring static files Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS . In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE . Store your static files in a folder called static in your app.
Static content is any content that can be delivered to an end user without having to be generated, modified, or processed. The server delivers the same file to each user, making static content one of the simplest and most efficient content types to transmit over the Internet.
Static files are meant for javascript/images etc, but media files are for user-uploaded content.
In general, it's a good idea to put static content - e.g. images, CSS and JS files - on a different server and, furthermore, on a different domain/subdomain. This allows the software that serves the static files to be highly optimized and blazingly fast (for example, nginx).
The other main benefit comes from decreases in network traffic. If you serve static content from the same domain as your dynamic Django app, then client browsers send your domain's cookies as part of their HTTP request, even for static files. This is unnecessary overhead - static files will always be static - but is required because the client can't tell the difference between static and dynamic content. If, on the other hand, the static content was being served from a different domain, then it could be configured as a "cookieless domain", thus minimizing request overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With