How to serve Django Statics (and not go insane)
blog.sendhub.com
blog.sendhub.com
I've tried django-compress and it was a nightmare, the old style synccompress was actually easier to setup and get working for some reason.. Was hoping for a better rolled solution.
Also, the part about cloudfront isn't written very clearly. I had to stop for a moment and think about what it meant. Great idea nonetheless. S3's gzip support sucks. For some odd reason (I don't support IE6..) the gzip from S3 was breaking on IE9. Worked fine on 8 and 10. Broke on 9. =/
Then I realized, oh they said cloudfront. So you could still technically keep your stuff in your S3 bucket, though you'd end up paying more for S3 originating transfer as well. In this case, cloudFRONT (the non amazon one!!) may be the better choice.
Hate that they sound the same. I even get my OWN THOUGHTS mixed up sometimes :(
Also, a static build process (a la require.js) solves a lot of these for you in a way that's not specific to Django or any other framework. You also don't end up bloating your web app code with the concern for how static files are to be processed, which I personally like a lot.
Another way to go is to use Google's mod_pagespeed [1], which once again is not framework-specific.
Lastly, you can try another trick where you pre-generate .gz versions of all the files too, to really speed things up. It's nice not to have to do things on the fly and web servers like nginx can take quite a lot of traffic serving static files, so you can hold off on going the CDN route, unless of course geography matters more to you than offloading server resources.
https://developers.google.com/speed/docs/best-practices/cach...
At any rate, I'm happy that you were able to get it working, Mike! That is really neat. Do you think you'll write a blog post about how you did it?
Were you simply unable to configure django-compressor (or any other pre-existing django statics library) properly?
An even worse problem is that you won't be able to transition to using async dependency loading for your JavaScript since there's no way to get the filenames of each compressed bundle that you'll need to pass to whatever lib you're using.
These problems don't apply much when you're just prototyping something, but it turned out to be an awful hole we dug ourselves into when we ran into severe performance bottlenecks with Django's template rendering and serving all our JS on page load.
In this case the 2 hours I spent implementing my own solution means it works exactly how I want it to and going forward it will be way easier to maintain.
1. The config was overly complex and not flexible enough for our needs.
2. It added extra, and unnecessary deploy steps which slowed down our deployments.
3. Configuring GZIP on S3 and Cloudfront is prohibitively complex.
CloudFlare on the other hand, solves many of these problems for us.
http://aws.typepad.com/aws/2010/11/amazon-cloudfront-support...
So unfortunately, cloudflare would be your only option.
Also, google's pagespeed service (in beta) is also an option. Also free, so that's good :D
EDIT: Okay, wrong again. Appears that cloudfront will serve dynamically gzipped content if your origin server responds with gzipped content to the Accept-Encoding header. So origin server = S3 is not a good idea, but origin through your own web server should work fine.
The only persistant problem that I haven't been able to iron out is that some non-US users of my application can't get any of our javascript assets to load in Google Chrome correctly. VPNing into a US IP seems to fix the problem. Has anyone else had any issues like this?
Have you filed a ticket with CloudFlare or contacted them about this problem?
What client doesn't have support for gzip?