Django Compressor Offline Inheritance
This issue is specifically for a production site using Django Compressor. I want this to work when COMPRESS_OFFLINE = True so that I can pre-compress all of my site's css files before pushing to production.
I would like to, within base.html, do the equivalent of this:
{% compress %}
{% block css %}
{% endblock %}
{% endcompress %}
so that all of my css blocks in files that extend base are compressed. This is mainly so that I don't have to add {% compress %} tags to all my child templates.
There are several similar issues on Stack Overflow, but I haven't found a good solution for doing this when compressing offline (ie with Django Compressor's compress management command). The surrounding compress tags work fine when COMPRESS_OFFLINE = False. Has someone found a way to make this work offline?
I'm listing a few similar threads that seem to pertain to non-offline solutions. The links in the second thread indicate that there have been past issues with inheritance when working with Django Compressor offline but perhaps they have been resolved:
Django-compressor and template inheritance
Does django-compressor work with template inheritance?
You have do use compress offline for that technique to work, but as long as you have caching set up properly, django-compressor will not re-compress on every request unless the resources have been changed.
I've used this technique to allow users to use lesscss to extend the site theme and use our mixins etc. It's a little wonky to get working but (in my experience so far) it's perfectly stable when configured correctly, and doesn't introduce a substantial request latency once it's compressed the first time.
You can set up a service like pingdom, blamestella, or new relic to hit various pages to ensure the compressed assets are always in cache (they monitor for uptime, but work for this as well)
链接地址: http://www.djcxy.com/p/68508.html上一篇: 压缩器和模板标签在Django