Change record status: 
Introduced in branch: 

All core JavaScript files are now defined as libraries. They explicitly define all of their dependencies on other JS and CSS files like jquery.js, drupal.js and Drupal.settings. This solves the Drupal 7 issue #1279226: jQuery and Drupal JavaScript libraries and settings are output even when no JS is added to the page. This change will make possible the use of core JavaScript in the context of modular JavaScript such as AMD or CommonJS.

Core now only loads the JavaScript that is needed to display the page, no more, no less.

To add a script.js file from a module that uses: jQuery, jQuery.once, Drupal, and drupalSettings

In D7:

drupal_add_js(drupal_get_path('module', 'MYMODULE') . '/script.js');

In D8:

  version: 1.0
    script.js: {}
    - core/jquery
    - core/drupal
    - core/drupalSettings
    - core/jquery.once
// Later in the module code.
$my_render_array['#attached']['library'][] = 'MYMODULE/foo';
Module developers
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
Not done


mondrake’s picture

Note that the Drupal settings library name for hook_library_info was changed from drupal.settings to drupalSettings to reflect the change on the javascript side. (see JavaScript settings moved from Drupal.settings to global drupalSettings variable)

nod_’s picture

Thanks for catching it, updated.

elachlan’s picture

Calls to drupal_add_library() will fail without a version being defined.

Otherwise they will get:
Notice: Undefined index: version in drupal_get_library() (line 3742 of core\includes\

awasson’s picture

If I am building a module that doesn't use hook_library_info(), how do I tell Drupal that I need to load jQuery?

For instance, I'm building a Drupal 8 module that uses the Libraries module to map and load a library found at /sites/all/libraries/myscripts.

It does exactly what it is supposed to do except the library won't run because it requires jQuery.

As a temporary workaround, I'm using hook_library_info() to load a blank script with dependencies on system jquery but I'm sure there is a clean way to do this. I just can't find it in the docs. Any direction would be great!