Implement Drupal.AjaxCommands as separate libraries

Created on 28 May 2025, 2 days ago

Problem/Motivation

Drupal.AjaxCommands includes js to support the full range of AJAX commands - insert/add_css/add_js/messages/replace/announce etc.

However, we don't need that API unless an AJAX request is made, and an AJAX response actually returns one of the commands.

The one exception to this rule is add_js (and maybe add_css) which is what we'd use to load these new libraries on demand.

Some pages are AJAX-enabled but won't necessarily make an AJAX request - pages with links that trigger dialogs, AJAX pagers, views AJAX filters etc. On these pages, we can load the absolute minimum JavaScript to serve the page, then use the AJAX system itself to load dependencies of specific AJAX commands. The result should be much lighter page weight.

Steps to reproduce

Proposed resolution

Add either a single AJAX commands library, or individual libraries for individual AJAX commands, and have each AJAX command #attach the necessary library it needs.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

ajax system

Created by

πŸ‡¬πŸ‡§United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @catch
  • πŸ‡ΊπŸ‡ΈUnited States fathershawn New York

    We need this only if if there is an existing capability we cannot implement using the tools provided by htmx - let's keep it a placeholder.

  • πŸ‡¬πŸ‡§United Kingdom catch

    Yeah that makes sense, if we have less commands, it's less js. Moving to [PP-1] on at least some of 🌱 Gradually replace Drupal's AJAX system with HTMX Active .

  • πŸ‡¬πŸ‡§United Kingdom catch

    Also wonder whether we could do something about ajax-progress.module.css in a similar way.

    e.g. could we move that to a separate library, and then have the AJAX system load it via loadcss so that it's non-blocking? Seems like more or less the definition of CSS styles that shouldn't need to be blocking. It's not impossible that a page immediately triggers and AJAX request but it's pretty uncommon.

Production build 0.71.5 2024