Skip to content

Instantly share code, notes, and snippets.

@Chronial
Last active June 5, 2016 10:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Chronial/45ce9f33615a3b24c51f to your computer and use it in GitHub Desktop.
Save Chronial/45ce9f33615a3b24c51f to your computer and use it in GitHub Desktop.
Whitenoise support for django compressor
from django.conf import settings
from whitenoise.django import DjangoWhiteNoise
class DjangoCompressWhiteNoise(DjangoWhiteNoise):
def __call__(self, environ, start_response):
# Handle files generated on the fly by django-compressor
url = environ['PATH_INFO']
if url.startswith(self.static_prefix) and url not in self.files:
if self.is_compressed_file(url):
self.files[url] = self.find_file(url)
return super().__call__(environ, start_response)
def is_compressed_file(self, url):
if not url.startswith(self.static_prefix):
return False
path = url[len(self.static_prefix):]
return path.startswith(settings.COMPRESS_OUTPUT_DIR + "/")
def is_immutable_file(self, path, url):
if self.is_compressed_file(url):
return True
else:
return super().is_immutable_file(path, url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment