Usage of async instead of defer for module js

Created on 17 June 2025, 17 days ago

Fine-tweaking the performance of my site, I recently reached to https://web.dev/articles/cookie-notice-best-practices and realised that the advice:

> Cookie notice scripts should be loaded asynchronously. To do this, add the async attribute to the script tag.

Should the js loaded at eu_cookie_compliance.module (around line 228) use an 'async' => TRUE instead of a 'defer' => TRUE ?

I'm not sure if this could have a downside somehow...

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇪🇸Spain joe_carvajal Seville (Spain)

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

Comments & Activities

  • Issue created by @joe_carvajal
  • 🇳🇿New Zealand atowl

    Hi @joe_carvajal,

    That defer is for the disabled scripts loader, so only gets enabled if there's something in the disabled scripts.

    After doing some reading, i'm not totally convinced yet that it would make much of a difference? Are you seeing any significant improvements by doing this?

    It could be an issue with drupal.behaviors, as the async wouldn't wait (fired straight after first file download), so its possible that if a disabled script is trying to enable a behavior then it might not work.

    Would be keen to hear more if anyone else has opinions before making the change, OR we could make it a configuration to be set?

Production build 0.71.5 2024