🔍 inp.works

Main thread bloccato: input delay alto prima ancora che il gestore parta

Cosa succede

L'input delay è il tempo tra il clic dell'utente e il momento in cui parte il tuo gestore di eventi. Il gestore può essere perfettamente veloce — ma se il main thread è nel mezzo di un task lungo (idratazione, init analytics, un timer che fa il parsing di dati), l'evento aspetta in coda finché quel task non finisce.

È l'unica fase dell'INP che il tuo gestore non può correggere, perché il colpevole è altro codice che era in esecuzione.

Come riconoscerlo

Come risolverlo

Problema

// at page load: one 800 ms task — every click during it waits
initAnalytics()
buildSearchIndex(allProducts)
prefetchRecommendations()

Soluzione

initAnalytics()
await scheduler.yield()                  // events can run between steps
buildSearchIndex(allProducts)
requestIdleCallback(() => prefetchRecommendations())
Scansiona il tuo sito gratis →
Advertise here