12

I need to use a different jQuery version. Currently, Drupal is using jQuery 3.2.1, but I need a previous version.

In Drupal 7 you could easily change jQuery version with the jQuery Update module. How can I achieve the same with Drupal 8?

3
  • The jquery_update module was meant for upping the version of jQuery back then, because the core version was almost never updated with the pace jQuery was moving. You could try the override method outlined here: drupal.org/node/2497313 - bear in mind that other core/contrib modules that rely on jQuery could break in 8.4.x using an older release of jQuery.
    – Kevin
    Oct 16 '17 at 14:23
  • Here is a similar question using the override/extend approach: drupal.stackexchange.com/q/200418/57
    – Kevin
    Oct 16 '17 at 14:25
  • See the "Overriding and extending libraries" section here: drupal.org/docs/8/theming-drupal-8/…
    – Kevin
    Oct 16 '17 at 14:25
18

Add your custom jQuery library in your mytheme.libraries.yml:

jquery-custom:
  remote: https://github.com/jquery/jquery
  version: "2.2.4"
  license:
    name: MIT
    url: https://github.com/jquery/jquery/blob/2.2.4/LICENSE.txt
    gpl-compatible: true
  js:
    js/jquery-2.2.4.min.js: { minified: true, weight: -20 }

Then override the core jQuery library in your mytheme.info.yml:

libraries-override:
  # Replace an entire library.
  core/jquery: mytheme/jquery-custom
2
  • 1
    This only sort of worked for me. When I override the core/jquery (even with the same version of jQuery) I get a whole load of .once() is not a function errors from drupal somewhere. Nov 26 '19 at 23:20
  • Note: This answer assumes that you've downloaded the jquery-2.2.4.min.js file and placed it in your my_theme/js/ dir. Also, this will not work in a module, only in a/the theme. May 3 '21 at 16:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.