6

此问题专门针对使用 Django Compressor 的生产站点。我希望它在 COMPRESS_OFFLINE = True 时工作,以便我可以在推送到生产之前预压缩我网站的所有 css 文件。

我想在 base.html 中执行与此等效的操作:

{% compress %}
    {% block css %}
    {% endblock %}
{% endcompress %}

这样我在扩展 base 的文件中的所有 css 块都被压缩了。这主要是为了让我不必将 {% compress %} 标记添加到我的所有子模板中。

Stack Overflow 上有几个类似的问题,但是我在离线压缩时(即使用 Django Compressor 的压缩管理命令)没有找到一个好的解决方案。当 COMPRESS_OFFLINE = False 时,周围的压缩标签可以正常工作。有人找到一种方法使这项工作离线吗?

我列出了一些似乎与非离线解决方案有关的类似线程。第二个线程中的链接表明,在离线使用 Django Compressor 时存在继承问题,但也许它们已经解决:

Django-compressor 和模板继承

django-compressor 是否适用于模板继承?

4

1 回答 1

0

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)

于 2012-08-01T14:56:30.393 回答