2

A bit of background... I'm setting up my new site's base template and I'm including some popular javascript libraries, such as AngularJS, Bootstrap's javascript files, and Underscore.js. Of course I wrap these files in {% compress js %}. Example code below:

{% compress js %}
    <script src="{{ STATIC_URL }}new_js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
    <script>window.jQuery || document.write('<script src="{{ STATIC_URL }}new_js/vendor/jquery-1.8.3.min.js"><\/script>');</script>
    <script src="{{ STATIC_URL }}new_js/vendor/bootstrap.js"></script>

    <!-- Angular -->
    <script src="{{ STATIC_URL }}new_js/vendor/angular.min.js"></script>
    <script src="{{ STATIC_URL }}new_js/angular/directives.js"></script>
    <script src="{{ STATIC_URL }}new_js/angular/services.js"></script>
    <script src="{{ STATIC_URL }}new_js/vendor/underscore-1.4.3.min.js"></script>

    {% block extra_js %}{% endblock %}
{% endcompress %}

I know django-compressor only runs the minification filters, so it's probably the minifiers not generating the correct Javascript output.

Here is the JS error I get with JSMin:

SyntaxError: invalid increment operand
http://localhost:8000/site_media/static/cache/js/0f5eb5fb3b24.js
Line 448

And the error from the file generated by SlimIt:

SyntaxError: missing ; after for-loop initializer
http://localhost:8000/site_media/static/cache/js/7fbdf61f5abb.js
Line 1

I'm not entirely sure what's going on here, it seems hard to believe the minifiers would generate incorrect files on these common js libraries.

Has anyone run into problems with django-compressor's Javascript filters messing up common libraries?

4

1 回答 1

1

我去了 IRC,有人给了我一个很好的提示。他们告诉我使用 Javascript 文件的非缩小版本。这样,您就可以在开发环境中进行调试。这解决了我的大部分问题。

最新版本的 Underscore.js 1.4.3 仍然存在问题,但已在他们的开发分支中修复。

https://github.com/jonthornton/jquery-timepicker也存在问题。所以我现在只是把它放在 {% nocompress js %} 中。

于 2012-12-20T05:30:46.093 回答