0

I have app.html page with many coffee scripts (58 files). I use django-compressor to compile them:

{% compress js %}
<script type="text/coffeescript" src="/static/scripts/commons/commons.coffee"></script>
<script type="text/coffeescript" src="/static/scripts/app/model/Storage.coffee"></script>
<script type="text/coffeescript" src="/static/scripts/app/model/Unit.coffee"></script>
....
{% endcompress %}

Everything compiles and works, but it takes 15 seconds for page to response. I think it should be ok for the first request (coffees should be compiled), but it takes same 15 seconds on the 2nd, 3rd and all further requests.

The output is always the same:

<script type="text/javascript" src="/static/CACHE/js/commons.33f0b9628e28.js"></script>
<script type="text/javascript" src="/static/CACHE/js/Storage.924e88456824.js"></script>
<script type="text/javascript" src="/static/CACHE/js/Unit.0fdebfecb96b.js"></script>
....

I don't change files, I just do page refresh.

Seems like django-compressor recompiles all files on every request (but names of compiled js files don't change, which is weird).

Any way I can speedup django-compressor?

P.S.

  • I run django locally by manage.py runserver.
  • DEBUG = True (my DEBUG option is set to True in settings.py)
imkost
  • 8,033
  • 7
  • 29
  • 47

2 Answers2

2

django-compressor now has a system for caching precompilers and speed up coffee compilation, only compiling files that have changed. This speeds up development response times.

https://github.com/django-compressor/django-compressor/pull/650

Simply add to your compressor settings:

COMPRESS_CACHEABLE_PRECOMPILERS = (
    'text/coffeescript',
)
maraujop
  • 4,472
  • 2
  • 36
  • 40
1

I guess you have set this COMPRESS_ENABLED = True. Set if False. Also take a look at COMPRESS_OFFLINE, so you can compress static manually offline:

$ python manage.py compress

This will drop cache key too. And check your COMPRESS_CACHE_BACKEND by the way.

byashimov
  • 454
  • 2
  • 6
  • If I set `COMPRESS_ENABLED = True`, all my coffees are combined into the one js file (which is not what I want for development, I want separate files), page refreshes now are fast, but when I modify one of the files, page refresh again takes 15 seconds. `python manage.py compress` is inconvenient for development. Can COMPRESS_CACHE_BACKEND change the situation? I've read the documentation, it says `The backend to use for caching, in case you want to use a different cache backend for Django Compressor.` But what does it mean? What does cache exactly do in context of django compressor? – imkost Oct 15 '14 at 22:30
  • If you use [DummyCache](https://docs.djangoproject.com/en/dev/topics/cache/#dummy-caching-for-development) it would NOT cache at all, that's what I mean. Yes, you should set COMPRESS_ENABLED = False to make it not compress your scripts every request with DummyCache. "but when I modify one of the files, page refresh again takes 15 seconds" then this is the problem. Your scripts are compiled too long. – byashimov Oct 16 '14 at 06:33
  • So, Django compressor can't recompile only those scripts that were changed since last page refresh? It can only compile all of them? – imkost Oct 16 '14 at 07:35
  • Unfortunately I don't use coffescript, so I don't know how it is compiled. Probably there are a better tools for instance compilation, so you can do this {% if DEBUG %}path to compiled script{% else %}{% compress js %}{% endif %}. Take a look at this [answer](http://stackoverflow.com/a/5061055/3951758). – byashimov Oct 16 '14 at 09:00
  • Yes, seems like using `coffee` command tool with `--watch` parameter would be more efficient in terms of page refresh speed. So django-compressor is not good for development (if you have many coffee files). Thank you, Murad – imkost Oct 16 '14 at 11:54