compressor creates javascript with syntax errors

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?


I went on IRC and someone gave me a good tip. They told me to use the non-minified version of Javascript files. That way, you can debug in development environment. That solved most of my problems.

There was still an issue with the latest version of Underscore.js 1.4.3, but it was fixed in their dev branch.

There was also an issue with https://github.com/jonthornton/jquery-timepicker. So I just put it in {% nocompress js %} for now.

链接地址: http://www.djcxy.com/p/68512.html

上一篇: 使用远程脚本的压缩程序(Google Maps API)

下一篇: 压缩器创建JavaScript语法错误