Created
November 28, 2015 22:19
-
-
Save jrief/7c597aadead7051a2d4f to your computer and use it in GitHub Desktop.
Replacement for django.contrib.staticfiles.finders.FileSystemFinder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
import os | |
from django.conf import settings | |
from django.contrib.staticfiles.finders import FileSystemFinder | |
class ServeUnminimizedFinder(FileSystemFinder): | |
""" | |
In debug mode, serve /static/any/asset.min.ext as /static/any/asset.ext | |
""" | |
locations = [] | |
serve_unminimized = getattr(settings, 'DEBUG', False) | |
def find_location(self, root, path, prefix=None): | |
if self.serve_unminimized: | |
# search for the unminimized version, and if it exists, return it | |
base, ext = os.path.splitext(path) | |
base, minext = os.path.splitext(base) | |
if minext == '.min': | |
unminimized_path = super(ServeUnminimizedFinder, self).find_location(root, base + ext, prefix) | |
if unminimized_path: | |
return unminimized_path | |
# otherwise proceed with the given one | |
path = super(ServeUnminimizedFinder, self).find_location(root, path, prefix) | |
return path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Upset to catch errors in third party Javascript code, which have been included as minimized versions?
By replacing
with
when in settings.py
DEBUG=True
and the unminimized files exists side by side with the included one, then serve the former oneinstead of the minimized file.