4 ms·
Front-side HTTP caches can be essential at giant scale. First they help with naturally-static content, then you can design to maximize the amount that can be HT
by gojomo 13y ago
Front-side HTTP caches can be essential at giant scale. First they help with naturally-static content, then you can design to maximize the amount that can be HTTP-cached.
I would like to see this better recognized as a usual and desirable production setup in the Django community, so as to eventually change the traditional doctrine around static resources.
Currently, there's the assumption that every serious production deployment moves static file-serving out of python/Django, to a dedicated side server. So, the interaction of the 'staticfiles' component changes awkwardly around the DEBUG setting, and the docs contain hand-wavey warnings about how using Django to serve static resources is "grossly inefficient and probably insecure".
Well, once you've committed to having a front-side HTTP cache, it's pretty damn efficient - one request per resource for an arbitrarily long cache-lifetime period. It requires fewer deployment steps and standalone processes than the assumed ('collectstatic'-and-upload-elsewhere) model. And if the staticfiles app is truly "insecure", that needs fixing: many people run their dev/prototype code in an internet-accessible way, so any known security risks here should get the same attention they get elsewhere. (Disabling the code entirely when DEBUG is true is a dodge.)
I'd love a future version of Django to embrace the idea: "staticfiles is a wonderful way to serve static resources, if you run a front-side HTTP cache, which most large projects will".
- eli 13y agoI'm a huge fan of Varnish as a caching proxy. But for just serving static assets, I'd suggest Amazon CloudFront. It's easy to set up, you only pay for what you use and you get all the benefits of a global CDN.
- mattrobenolt 13y agoCloudFront is slow. :) Check out Fastly.
- eli 13y agoI demoed it a while ago, maybe I'll take another look. My real point was that you don't need to install any unfamiliar software. I love Varnish, but if the default VCL file doesn't work for you, there's a learning curve.
- gojomo 13y agoCloudFront... Fastly... CloudFlare... I'd agree that many projects should just adopt a cache-as-a-service, rather than add another layer/process that must be learned and maintained to their own systems.
- mattrobenolt 13y agoSure. Any CDN is better than no CDN. :)
- eli 13y ago$50 monthly minimum at fastly means it's not a great plug-and-play replacement for smallish sites.
- mattrobenolt 13y agoI think what I'd like to get across more is that a lot of our dynamic content can be "static" as well, without going the static files route. Being static for shorter periods of time is something that we can achieve with Varnish, and it's definitely an overlooked concept in the community.