Skip to content

Comments

feat: use requestIdleCallback for delayed script loading#586

Open
fkakatie wants to merge 2 commits intomainfrom
idle-delayed-loading
Open

feat: use requestIdleCallback for delayed script loading#586
fkakatie wants to merge 2 commits intomainfrom
idle-delayed-loading

Conversation

@fkakatie
Copy link
Member

@fkakatie fkakatie commented Feb 5, 2026

Addresses discussion in #583 and relates to #376 and #408

This PR implements the requestIdleCallback approach proposed by @ramboz in discussion #583.

Changes

  • Modified loadDelayed() to use requestIdleCallback when available
  • Loads delayed scripts only when CPU has spare capacity or falls back to existing 3-second setTimeout for browsers without support (only ~82% coverage as of this comment)
  • Prevents INP and TBT issues

Benefits

  • Better performance: No artificial delays or user interaction requirements
  • Predictable behavior: Loads for all visitors
  • Progressive enhancement: Modern browsers get optimal loading, older browsers get current behavior
  • Non-breaking: Consent handling remains separate, scripts in delayed.js unaffected

Test URLs:

@aem-code-sync
Copy link

aem-code-sync bot commented Feb 5, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run PSI checks
  • Re-sync branch
Commits

@aem-code-sync
Copy link

aem-code-sync bot commented Feb 5, 2026

Page Scores Audits Google
📱 / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI
🖥️ / PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS PSI

Co-authored-by: Julien Ramboz <ramboz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants