Website speed directly impacts organic search rankings, user retention, and conversion rates. With Google's emphasis on Interaction to Next Paint (INP), performance optimization requires a relentless focus on main-thread efficiency.
1. Taming Interaction to Next Paint (INP) with scheduler.yield()
INP measures the latency of every user interaction throughout the entire lifecycle of a page. Jab heavy JavaScript tasks main thread ko block karte hain, clicks and keypresses feel sluggish. Use scheduler.yield() to break up long tasks:
async function processLargeDataset(items) {
for (const item of items) {
processItem(item);
// Yield execution back to browser to process pending user input
if ('scheduler' in window && 'yield' in scheduler) {
await scheduler.yield();
}
}
}2. Accelerating Largest Contentful Paint (LCP)
To achieve an LCP under 1.2 seconds:
- Inlined Critical CSS: Embed core styles directly in the document head to eliminate render-blocking HTTP roundtrips.
- Priority Fetch Hints: Tag above-the-fold hero images with
fetchpriority="high"anddecoding="async". - Self-Hosted Optimized Fonts: Use
font-display: swapto avoid FOIT (Flash of Invisible Text).
3. Zero Cumulative Layout Shift (CLS)
Always declare explicit width and height attributes or aspect-ratio CSS properties on all media, banners, and dynamically injected embeds.