This module brings back the original jQuery.once() by RobLoach and with that jQuery to avoid all JS code that used the old dependencies and once syntax having to be rewritten.

This module overwrites core/jquery and core/jquery.once libraries, so you do not have to change a single line of code.

Features

  • Overwrites core/jquery library with a local copy of jQuery (currently 3.7.1)
  • Re-adds core/jquery.once library with a local copy of jQuery.once() (currently 2.2.3) that was used up until Drupal 9
  • Adds these two libraries also as seperate depencies for targeted use (jquery_once/jquery and jquery_once/jquery.once)

Benefits

  • You can use all modules that did not yet or won't switch to the new core/once library
  • If you simply like jQuery, you can use it regardless if Drupal core decides to drop its dependencies to it.
  • With a simple install of this module, you don't have to change a single line of code. Just continue using core/jquery and core/jquery.once like you did before.
  • Keep your site reliable, safe and especially maintainable for the future

Examples

You can keep using your old library definitions if you like. See below for an example of your_module.libraries.yml:

# You can keep using your core/jquery and core/jquery.once dependencies
my_js_logic:
  version: VERSION
  js:
    js/my_super_reliable_code.js: {}
  dependencies:
    - core/drupal
    - core/jquery
    - core/jquery.once

# You can also make new logic and specifically rely on the jQuery.once library
my_other_new_js_logic:
  version: VERSION
  js:
    js/some_new_file.js: {}
  dependencies:
    - core/drupal
    - jquery_once/jquery.once
Supporting organizations: 
Funded development

Project information

Releases