4

I am trying to compress my css and js files and serve as gzip file, but with no success.

I have tried all methods, django-pipeline, django-compressor etc.

I got django-compressor to create the gzip files but I am not sure how to serve them. I use GzipMiddleaware to compress and serve my html files.

Can any one please write step by step guide on how gzip and serve static files on heroku django.

Sorry to ask for detailed steps, I am not asking to be spoon fed, but am stuck with this issue for almost 24 hours now, tried n number of solutions, but none seems to work.

FYI, I am using django-1.5

Thanks in advance for your help

2
  • what are you using to serve your staticfiles? are you pushing them to s3, or serving them through django? Commented Nov 25, 2013 at 6:04
  • @Thomas I am serving static files through django and serving media files through s3. Commented Nov 25, 2013 at 12:26

2 Answers 2

2

You should seriously consider uploading your static files to s3 as well. Django is really not cut out for serving files, and it will consume precious resources on your app server to do so.

Here's some great reasons for using s3 for staticfiles. http://blog.doismellburning.co.uk/2012/07/14/using-amazon-s3-to-host-your-django-static-files/

Here's a article explaining how to get S3 to serve gzipped resources: http://www.jamiebegin.com/serving-compressed-gzipped-static-files-from-amazon-s3-or-cloudfront/

Here's a storage backend that will collectstatic to s3.

You could probably easily write a storage backend that gzips and upload to s3 by subclassing this backend and django-compressor's backend.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your help. But few of my users access my website behind firewall which blocks amazon s3. To ensure basic working of the website to all audience I decided to not to use aws for static content. Can you please assist in terms of serving composed static files via django.
I assure you, gzipping your static files will not have any appreciable impact on your pageload times. The bottleneck is that you're serving static files from your application server, without caching or etags, behind a loadbalancer that can't cache any of it. If you want to shoot yourself in the foot for the sake of a couple of a "few" users with retarded firewalls, fine; but I won't show you where the gun is kept.
Thomas thanks for your insights. I couldn't agree more but the few users happen to be very important visitors of my website to ignore. Let me try to find better alternative either a CDN which is accessible everywhere. Thanks for your help. Any one with other thoughts please.
Thanks Thomas. I am now using gae to serve static files, django compressor was quite tricky had to write bash scripts to take care of manual work.
0

I had the exact same issue. I was using grunt but found there was a lot of extra config etc etc etc then I found django-compressor which is AWESOME!

But I deploy to Heroku which doesn't gzip anything and relys on the app to do it.

I couldnt find any wsgi wrapper that served pre-compressed gzip files, so I extended dj-static to do it for me. Check out my fork of dj-static which includes the additions. Basically it will check for a corresponding static filename that ends in .gz and if it finds it, it will serve it instead. I use this for my Heroku projects.

https://github.com/hdickson/dj-static

To test on your dev server if you run the django built in web server be sure to run it with the --nostatic command line switch. ie python manage.py runserver 0.0.0.0:80 --nostatic

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.