Change record status: 
Project: 
Introduced in branch: 
7.x
Introduced in version: 
7.36
Description: 

Before Drupal 7.36, Drupal 7 always added jQuery and other related JavaScript libraries to all pages, even when they were not being used. For example, an anonymous user visiting the front page of a fresh Drupal installation would have these files loaded, even though no actual JavaScript runs on the front page.

In Drupal 7.36, an optional method was introduced to improve front-end performance by allowing sites and module authors to not force these libraries to be loaded on pages where they are not going to be used.

New "javascript_always_use_jquery" variable for sites to opt out of always loading the JavaScript libraries

Sites can now set the new "javascript_always_use_jquery" variable to FALSE if they want to turn on the above-mentioned functionality. There is no user interface for setting this variable currently, but it can be done in various common ways, for example by putting this code in settings.php:

$conf['javascript_always_use_jquery'] = FALSE;

This variable should be used with caution, because it will cause jQuery and related libraries to only be loaded on pages where Drupal's JavaScript API was used to include JavaScript files that require them. This should be safe on sites that always use the JavaScript API to load JavaScript, but if the site includes JavaScript in other ways (for example, hardcoded <script> tags in the theme, or in node bodies in the database) and if the JavaScript included there relies on jQuery but doesn't load it explicitly, setting this variable could cause broken JavaScript on the site.

If the variable is not set, the current behavior of Drupal 7 will not change.

New 'requires_jquery' option in drupal_add_js() which can be used by developers to indicate that a JavaScript file does not require jQuery

If you are a module or theme developer adding a JavaScript file which has no dependency on jQuery, it is recommended that you set the new 'requires_jquery' option to FALSE when adding the file via drupal_add_js(), $form['#attached']['js'], or similar methods. For example:

drupal_add_js('path/to/some/standalone-javascript-library.js', array('requires_jquery' => FALSE));

This will indicate to the JavaScript API that this file does not require adding jQuery to the page. (The default is to assume that it does.)

Be aware that if your JavaScript file uses any of Drupal's built-in JavaScript helper methods, such as the Drupal behaviors system or the Drupal.t() function, your code does require jQuery indirectly (even if you are not using jQuery methods directly yourself). This new option is primarily intended for JavaScript code written outside of Drupal, e.g. external libraries that do not rely on jQuery at all.

Impacts: 
Site builders, administrators, editors
Module developers
Themers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done

Comments

Dale Baldwin’s picture

You just made every AngularJs developer who works with Drupal smile ear to ear.