Build your JavaScript With jQuery 1.5.2 in Drupal 7

Shortly after Drupal 7 launched the version of jQuery shipped with Drupal became outdated. Drupal 7 ships with jQuery 1.4.4 but the jQuery community has shipped jQuery 1.5.2. When we are developing the JavaScript in our shinny new Drupal 7 we are already using an outdated version of jQuery. But, there is a solution. The jQuery Update module provides an update for core to jQuery 1.5.2 and jQuery UI 1.8.11.

If you are writing a Drupal 7 module that uses jQuery please consider depending on jQuery Update or at least make sure the script works with jQuery 1.5.2.

CDN Support

As an added bonus, a new feature in jQuery Update 7.x-2.2 makes it worth using for all sites. It provides integration with the Google and Microsoft CDNs for both jQuery and jQuery UI. In the performance admin settings page there is a selector to choose where to get jQuery from.

Providing Minimized and Full Source Script Versions

The jQuery Update module stores if the JavaScript should be served in a Development (full source) or Production (minified) version. When Development is chosen the full scripts are served which makes debugging and developing easier.

This feature is something other modules can tap into. This state of the JavaScript is stored in the Drupal variable jquery_update_compression_type. The possible values are min and none. That means modules can provide both a production version and a development version of their JavaScript with easy access to switch between them. An example with the script versions script.js and script.min.js:

$min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
drupal_add_js('path/to/script' . $min . '.js');

Two modules already tapping into this are the bibly and underscore modules.

As as we crank out Drupal 7 websites lets create some awesome JavaScript.