In the new spirit of information sharing and "Best Practices[tm]" I
wanted to take a moment to introduce those of you who've not heard of
these packages and are using Django (Playdoh).
## Django-Pipeline [0] ##
It's a JS/CSS aggregator, compiler, and minifier in the vein of
django-compressor. It's more like jingo-minify in that you create your
media bundle definitions in your settings file instead of the templates.
This means no dependence on lxml and cumbersome parsing of HTML with
python, as well as being one central spot to easily see how your media
is laid out so you can spot redundancies or slight variations that can
cause large un-cached downloads for browsers. It also centralizes the
templates for your media tags, which are customizable globally or on a
per-bundle basis. It supports compilation with all of the major CSS and
JS pre-processors, as well as making it easy to add your own. It even
supports easy inclusion of JS templates and various JS templating
systems (though a severe lack of Nunjucks). And of course it supports
both Django Templates and Jinja2.
Perhaps the best part is that it seamlessly integrates with Django's
staticfiles framework (thanks Jezdez!). The whole thing runs as a hook,
so the only command that needs to be run is "./manage.py collectstatic",
and it automatically understands any changes made by any staticfiles
backend mixins.
## WhiteNoise [1] ##
This is a WSGI middleware (so not Django specific, though does have some
Django hotness built in) that serves your static media via your WSGI
process(es). I know, that sounds daft, but hear me out.
You should be using a CDN. Seriously. So how fast (or not) the files are
served from your app-server is mostly irrelevant (though it uses the
sendfile system calls to serve the files so it isn't slow). The
advantages you get, however, are many.
1. When used with Django and the staticfiles backends that add a hash to
the names of your files, it understands that naming convention and adds
very long expires headers automatically to those files, along with a
configurable default expire to the others (1 hour by default).
2. Provides a backported ManifestStorage backend from Django 1.7 that
uses a JSON manifest file to store and discover your hashed names
instead of on-the-fly calculation or using the cache.
3. Provides a gzip version of the backend from #2 that will pre-gzip all
of your appropriate files, then serve those if the request has the
correct Accept-Encoding header and adds the proper Vary header to the
response.
4. Allows very easy local running of your full production site by
relegating Nginx (or Apache) to mostly just an SSL terminator and proxy.
5. Allows you to set a folder that will act as a place for files that
should be served from the root if requested (e.g. robots.txt or
favicon.ico).
More is in the docs of course. I've submitted an issue to Playdoh [2] so
we can discuss this stack as a possible option along-site or replacement
for django-compressor and jingo-minify.
[0]
http://django-pipeline.readthedocs.org/
[1]
http://whitenoise.evans.io/
[2]
https://github.com/mozilla/playdoh/issues/173
This stack is currently running quite successfully on
https://scrumbu.gs
if you want to see it in action. I'm very interested to hear what you
think either here or in the issue [2].
Thanks,
--
Paul [pmac] McLanahan
Web Developer
Mozilla Web Productions