문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top