Adds the ability to differentially serve JavaScript on the basis of whether the current browser supports ES6 modules or not. This allows users to pay less of a penalty for when a site needs to support older browsers.

There is some extra wrangling to support edge cases where a browser may not respect the nomodule attribute and would then potentially execute more scripts than desired.

Usage

In extension.libraries.yml:

scripts:
  js:
    modern.js: { differential_serve: 'modern' } # ES6 only.
    legacy.js: { differential_serve: 'legacy' } # ES5 only.

Gotcha: initial attached legacy scripts may not get their Drupal behavior attach() methods called on the initial page load, due to the async nature of their loading.

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • caution Maintenance fixes only
    Considered feature-complete by its maintainers.
  • Module categories: Developer Tools, Performance
  • Created by Wongjn on , updated
  • shieldStable releases for this project are covered by the security advisory policy.
    Look for the shield icon below.

Releases