jQuery compiled with Google Closure Compiler

后端 未结 10 839
抹茶落季
抹茶落季 2020-11-29 04:52

Has anyone compiled jQuery against Google\'s newly-released Closure compiler?

There has been reported huge savings in code size. I\'m curious what the benefit is if

相关标签:
10条回答
  • 2020-11-29 05:33

    I tried with jQuery jQuery 1.3.2

    jQuery-1.3.2.min.js     57254 Bytes
    jQuery closure compiler 49730 Bytes
    -----------------------------------
    Reduced by               7524 Bytes
    Saved 13.31% off the original size
    Saved 10.87% off the gzipped size
    

    Gain of ~7KB

    But it also reports 15 Warnings and I didn't test if it still works

    0 讨论(0)
  • 2020-11-29 05:33

    jQuery is not compatible (yet) with the Closure Compiler in advanced mode. I agree it would be a very good thing to make it compatible, because its method-chaining syntax lends very readily to prototype virtualization for much improved execution speed.

    In fact, among the popular JavaScript libraries (other than Closure Library, that is), only the Dojo Toolkit is compatible with Closure Advanced mode.

    http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t

    0 讨论(0)
  • 2020-11-29 05:35

    Out of curiosity, I put together a SlickSpeed test of the latest Prototype and jQuery libs, shrunk with YUI and Closure. You can run the tests here.

    As others have noted, compiling with ADVANCED_OPT does not work but if someone wants to do the work, I'll be happy to add the results to the SlickSpeed test.

    0 讨论(0)
  • 2020-11-29 05:36

    The closure compiler eliminates any code that you don't actually use. The typical web page will only use a small fraction of jQuery functions, so the most benefit will come from compiling your code together with the full version of jQuery.

    0 讨论(0)
  • 2020-11-29 05:37

    With ADVANCED_OPTIMIZATIONS turned off:

    • jquery-1.3.2.min.js: 57254 bytes
    • jquery-1.3.2.closure.js 55346 bytes (-3.4%)
    • jquery-1.3.2.min.js.gz: 19680 bytes
    • jquery-1.3.2.closure.js.gz: 18666 bytes (-5.2%)

    With ADVANCED_OPTIMIZATIONS turned on: it doesn't work unmodified. With ADVANCED_OPTIMIZATIONS turned on and everything I can find to export exported... it still doesn't quite work, and the code is already up to 53466 bytes again (and 18785 gzipped, which is more than the gzipped closured code without ADVANCED_OPTIMIZATIONS) so it doesn't look like a winning proposition.

    0 讨论(0)
  • 2020-11-29 05:42

    As of jQuery 1.4, Google's Closure Compiler is used as the default minification technique for jQuery releases. However, jQuery only uses the SIMPLE_OPTIMIZATIONS settings. The jQuery team has no plans to support ADVANCED_OPTIMIZATIONS.

    0 讨论(0)
提交回复
热议问题