Search code examples
djangodjango-compressor

Django-compressor: Enable BrotliCompressorFileStorage with offline compression mode


I'm using offline compression in conjunction with whitenoise on heroku and everything works fine before I overrode COMPRESS_STORAGE to enable broli compression as below:

INSTALLED_APPS += ['compressor', ]
STATICFILES_FINDERS += ['compressor.finders.CompressorFinder',]
COMPRESS_STORAGE = 'compressor.storage.BrotliCompressorFileStorage'
COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True)
COMPRESS_OFFLINE = env.bool('COMPRESS_OFFLINE', default=True)

I have brolipy installed and added to requirements.txt.

But django-compressor gives me this error message:

module "compressor.storage" does not define a "BrotliCompressorFileStorage" attribute/class

Any idea why? The spelling seems correct. I checked the source code, and there is indeed a class named BrotliCompressorFileStorage in the compressor.storage module.

https://github.com/django-compressor/django-compressor/blob/develop/compressor/storage.py


Solution

  • As noted in https://github.com/django-compressor/django-compressor/issues/914, the brotli storage is not yet available in a django-compressor release, so you need to install the develop branch of django-compressor.