Django-compressor and template tags in Django

2019-08-14 04:29发布

Recently I have tried Django-Compressor. It's awesome and i like it too much, but i am having some troubles with offline compression (COMPRESS_OFFLINE = True) and template tags.

I have {{ django_vars }} and {% django_tags %} inside my JS code and i guess Google Clousure compiler (the filter what i'm using with Django-Compressor) doesn't know to identify them. In fact, I think Django template structures like {% if something %} are deleted.

How can i do to keep all this template vars/tags in my code JS after compressing?

Thanks mates.

Edit: Finally, i discovered all problems that i got using COMPRESS_OFFLINE, they all occurred due to a bug. They were not about Django syntax inside of JS code. The bug always appeared when you tried to compress JS code inside of a file .html, not a external JS. It failed with all parsers and all compilers/compressors.

Now, although i like more django-compressor than django-pipeline, i'm using this last one. At this moment, no problem reported with compression.

Thanks to all who tried to help me.

1条回答
Root(大扎)
2楼-- · 2019-08-14 04:58

Have you tried that? JS compiler of Django Compressor gets into work AFTER template nodes are rendered, IMO. Thus the {{ django_vars }} or {% django_tags %} are already replaced by their outputs in templates before being compressed.

If {{ django_vars }} or {% django_tags %} are changed per-view/template. It can not be compress to one piece of code. You'd better to move those parts from main JS code blocks to JS block and compress it separately.

查看更多
登录 后发表回答