Skip to content

Using the AMD Optimizer with jQuery

rbackhouse edited this page Mar 3, 2012 · 7 revisions

Now that jQuery is AMD friendly it’s possible to write AMD + jQuery applications that use the Zazl Optimizer for optimization/compression. Assuming that you have downloaded a copy of jQuery 1.7.x :

  • Follow the “Create a JEE Web Application” details from github.com/zazl/optimizer/wiki/Getting-Started-with-the-AMD-Optimizer for setting up a Zazl Optimizer enable WebApp.

  • Place the “jquery-1.7.x.js” file in a directory path “lib/jquery”.

  • In your “zazl” entry point provide a “paths” configuration that points to the location of “jquery-1.7.x.js”

    zazl({ 
        paths : { 
            jquery: "lib/jquery/jquery-1.7.1" 
        }
    }, 
    ["jquery"], 
    function($) {
    });
  • jquery-mobile is also now AMD enabled, although to obtain this version you must grab it from its github repo and build yourself. Assuming that the jquery-mobile module has been downloaded and place in a directory path “lib/jquery-mobile/” the above js snippet would now look like :

    zazl({ 
        paths : { 
            jquery: "lib/jquery/jquery-1.7.1",
            jquerymobile: "lib/jquery-mobile/jquery.mobile"  
        }
    }, 
    ["jquery", "jquerymobile"], 
    function($) {
    });

Clone this wiki locally