Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gzip not working in Django with Whitenoise

I have a Django website deployed on Heroku, using Whitenoise for serving static files.

The static files work fine but Gzip is not working according to various websites that I used to test it (including google tools).

this is the code in my production settings files:

DATABASES['default'] = dj_database_url.config()


SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

My static files configuration:

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

STATIC_URL = '/static/'
STATIC_ROOT = 'staticfiles'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

my wsgi.py file

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sikumim.settings")

application = get_wsgi_application()

#HEROKU DEPLOYMENT

from whitenoise.django import DjangoWhiteNoise
application = DjangoWhiteNoise(application)

what could be the cause?

I ran a few commands suggested in the comments, looks like gzip isn't working:

➜ ~ curl -I -H "Accept-Encoding: gzip" http://127.0.0.1:8000/

HTTP/1.0 200 OK
Date: Mon, 17 Aug 2015 13:56:02 GMT
Server: WSGIServer/0.2 CPython/3.4.0
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Content-Type: text/html; charset=utf-8
Set-Cookie:  csrftoken=SsgKEp76HDhG5L7otWxqBJeMyb00Vp03; expires=Mon,      15-Aug-2016 13:56:02 GMT; Max-Age=31449600; Path=/

➜ ~ curl -I -H "Accept-Encoding: gzip" http://www.sikumia.co.il

HTTP/1.1 200 OK
Connection: keep-alive
Server: gunicorn/19.3.0
Date: Mon, 17 Aug 2015 13:57:37 GMT
Transfer-Encoding: chunked
X-Frame-Options: SAMEORIGIN
Vary: Cookie
Content-Type: text/html; charset=utf-8
Set-Cookie: csrftoken=23M5ODiFKRnU3fDYMe3j2Rn3dwtCsNMX; expires=Mon, 15-Aug-2016 13:57:37 GMT; Max-Age=31449600; Path=/
Via: 1.1 vegur
like image 592
davegri Avatar asked Aug 04 '15 12:08

davegri


People also ask

What is WhiteNoise in Python?

Radically simplified static file serving for Python web apps. With a couple of lines of config WhiteNoise allows your web app to serve its own static files, making it a self-contained unit that can be deployed anywhere without relying on nginx, Amazon S3 or any other external service.


1 Answers

WhiteNoise only enabled gzip for your static files, not for your entire site, so you need to check one of your static files e.g

curl -I -H "Accept-Encoding: gzip" http://www.sikumia.co.il/static/some-file.css
like image 58
D. Evans Avatar answered Oct 12 '22 00:10

D. Evans