jQuery compiled with Google Closure Compiler

后端 未结 10 840
抹茶落季
抹茶落季 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:42

    I tried with their online compiler, it works well.

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

    Doesn't Closure just minimize and renames vars? jQuery already has a .min version. Minifying with closure again will probably be minimally helpful and potentially dangerous.

    Edit: I just did it.

    Compilation was a success!
    
    Original Size:  55.91KB (19.28KB gzipped)
    Compiled Size:  54.05KB (18.28KB gzipped)
    Saved 3.34% off the original size (5.18% off the gzipped size)
    

    This is on top of the already mined version. There's a demo here: http://closure-compiler.appspot.com/home

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

    John Resig reported a bug on recursive functions when he attempted to compile a nightly of jQuery 1.4, so there are a few kinks to be worked out. I wouldn't use a jQuery compiled with Closure Compiler without making sure it passes the jQuery testbed.

    http://code.google.com/p/closure-compiler/issues/detail?id=1&can=1#c2

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

    I used Closure (with ADVANCED_OPTIMIZATIONS) to compress the javascript code for a single-page site that I host and saw a significant size savings over the YUI Compressor. So I started looking into shrinking jQuery for that site as well, since it certainly doesn't use the entier jQuery library.

    I get warnings every time I run jQuery through the compiler, mostly pointing out portions of the code that are not used. Even still, the compiled code doesn't work. The primary issue I see is that things aren't being exported properly by the compiler. I was able to easily export functions from my own code by attaching them to the window object, but I have not yet been able to do this yet with jQuery.

    The good news is that John Resig is already experimenting with Closure. I suspect that we'll see new releases of both that are compatible in the near future.

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