logo

Extra Block Types (EBT) - New Layout Builder experienceâť—

Extra Block Types (EBT) - styled, customizable block types: Slideshows, Tabs, Cards, Accordions and many others. Built-in settings for background, DOM Box, javascript plugins. Experience the future of layout building today.

Demo EBT modules Download EBT modules

âť—Extra Paragraph Types (EPT) - New Paragraphs experience

Extra Paragraph Types (EPT) - analogical paragraph based set of modules.

Demo EPT modules Download EPT modules

Scroll

How to rewrite jQuery Cookie, core/js-cookie library in Drupal with the js_cookie module

02/03/2026, by Ivan

Why this change?

Migration path overview

1) Drupal 8 → 9: jQuery Cookie → core/js-cookie

Historical context: Drupal 9 replaced jQuery Cookie with js-cookie and provided code and library mapping examples. https://www.drupal.org/node/3104677

# BEFORE (Drupal 8 / early 9)
my_library:
  js:
    js/my_library.js: {}
  dependencies:
    - core/jquery
    - core/jquery.cookie
    - core/drupal
// BEFORE (jQuery Cookie API)
(($, Drupal) => {
  Drupal.behaviors.myModule = {
    attach: () => {
      $.cookie('cutest', 'red panda');
      const myCookieValue = $.cookie('cutest');
      $.removeCookie('cutest');

      $.cookie.json = true;
      $.cookie('cutest', { animal: 'red panda' });
    },
  };
})(jQuery, Drupal);

After (Drupal 9) you depended on core/js-cookie and used Cookies.* API: https://www.drupal.org/node/3104677

# AFTER (Drupal 9)
my_library:
  js:
    js/my_library.js: {}
  dependencies:
    - core/drupal
    - core/js-cookie
// AFTER (Drupal 9, js-cookie API)
((Drupal, Cookies) => {
  Drupal.behaviors.myModule = {
    attach: () => {
      Cookies.set('cutest', 'red panda');
      const myCookieValue = Cookies.get('cutest');
      Cookies.remove('cutest');

      Cookies.set('cutest', JSON.stringify({ animal: 'red panda' }));
      const cutest = JSON.parse(Cookies.get('cutest') || 'null');
    },
  };
})(Drupal, window.Cookies);

2) Drupal 10.1+ and 11: core/js-cookie → contributed js_cookie

Since Drupal core deprecated core/js-cookie in 10.1 and removed it in 11, you must replace it with the contrib JS Cookie module’s library: js_cookie/js-cookie. https://www.drupal.org/node/3322720

Composer

composer require drupal/js_cookie

This installs the module that exposes a Drupal asset library for the upstream js-cookie package. https://www.drupal.org/project/js_cookie

Declare a module/theme dependency (for contrib/custom projects)

# my_module.info.yml (or your theme's .info.yml)
name: My Module
type: module
core_version_requirement: ^10 || ^11
dependencies:
  - js_cookie:js_cookie

The project page explicitly notes adding js_cookie:js_cookie as a dependency for contrib modules (and to require drupal/js_cookie in composer if your module has its own composer.json). [4](https://www.drupal.org/project/js_cookie)

Switch your asset library dependency

# Replace this (deprecated in 10.1, removed in 11)
# - core/js-cookie

# With this (provided by the contrib module)
my_library:
  js:
    js/my_library.js: {}
  dependencies:
    - core/drupal
    - js_cookie/js-cookie

This exact replacement is the path recommended in the core change record announcing the deprecation. [2](https://www.drupal.org/node/3322720)

JavaScript code

Your JS code does not need changes if you already used the Cookies API from js-cookie—only the library dependency changes. [2](https://www.drupal.org/node/3322720)

((Drupal, Cookies) => {
  Drupal.behaviors.myModule = {
    attach: () => {
      // Set a cookie.
      Cookies.set('cutest', 'red panda', { path: '/', sameSite: 'Lax' });

      // Get a cookie.
      const myCookieValue = Cookies.get('cutest');

      // Remove a cookie.
      Cookies.remove('cutest', { path: '/' });

      // Store/retrieve JSON safely.
      Cookies.set('cutest', JSON.stringify({ animal: 'red panda' }));
      const cutestRaw = Cookies.get('cutest');
      const cutest = cutestRaw ? JSON.parse(cutestRaw) : null;
    },
  };
})(Drupal, window.Cookies);

Tip: js-cookie is RFC 6265–compliant and encodes values differently than the old jQuery Cookie, especially for JSON. The Drupal 9 change record outlines these behavior differences. https://www.drupal.org/node/3104677

Examples from the ecosystem

Step-by-step upgrade recipes

A) From jQuery Cookie directly to js_cookie/js-cookie (Drupal 10+)

  1. Remove core/jquery and core/jquery.cookie dependencies from your .libraries.yml. https://www.drupal.org/node/3104677
  2. Add js_cookie:js_cookie to your .info.yml dependencies (for contrib/custom modules and themes). https://www.drupal.org/project/js_cookie
  3. Change your library dependency to js_cookie/js-cookie. https://www.drupal.org/project/js_cookie
  4. Rewrite JS from $.cookie to Cookies.* as shown above. https://www.drupal.org/node/3104677

B) From core/js-cookie to js_cookie/js-cookie (Drupal 10.1 → 11)

  1. Require the module: composer require drupal/js_cookie. https://www.drupal.org/project/js_cookie
  2. (Contrib) Add js_cookie:js_cookie in .info.yml; just enable the module https://www.drupal.org/project/js_cookie.
  3. In .libraries.yml, replace core/js-cookie with js_cookie/js-cookie. https://www.drupal.org/node/3322720
  4. Keep your existing Cookies.* JS code. No functional changes needed. https://www.drupal.org/node/3322720

Gotchas and best practices