This module restores the original jQuery.once() functionality for Drupal. It allows modules that rely on the older jQuery and jQuery.once libraries to continue working without code changes.
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/jquerylibrary with a local copy of jQuery (currently 3.7.1) - Re-adds
core/jquery.oncelibrary 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/jqueryandjquery_once/jquery.once)
Benefits
- You can use all modules that did not yet or won't switch to the new
core/oncelibrary - 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/jqueryandcore/jquery.oncelike 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
Ask your assistant about Bring Back jQuery.once()
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.