Reduce the JavaScript that blocks the page while it loads
Why it matters
Total Blocking Time is a lab number that measures how long scripts keep the page from responding while it loads, and it is used here because real interaction data was missing. A high value means the page is likely to feel sluggish.
Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.
The fix
- Find what blocks the main thread while the page loads. Run Lighthouse (in Chrome DevTools or PageSpeed Insights) and open the audits "Reduce JavaScript execution time", "Minimize main-thread work" and "Reduce unused JavaScript". Record a load in the DevTools Performance panel with the CPU throttled; long tasks are marked in red, and the bottom-up view shows which script owns them.
- Remove or delay third-party scripts (tag managers, chat widgets, A/B testing, heatmaps, social embeds) until the visitor needs them, and load your own scripts that are not needed for the first view with defer or as modules.
- Ship less JavaScript. Drop libraries you do not use, split the bundle so each page loads only its own code, and load heavy widgets on demand, for example when the visitor clicks, with a dynamic import.
- Break long tasks into smaller pieces that yield to the browser between them, so the page can respond while it loads.
- Run Lighthouse again a few times, since lab numbers vary from run to run. Total Blocking Time is a lab number; real interaction speed shows up as INP once Google has enough field data for the page.
html
<script src="/js/app.js" defer></script> <script type="module"> // load a heavy widget only when the visitor asks for it document.querySelector('#chat-button').addEventListener('click', async () => { const { openChat } = await import('/js/chat.js'); openChat(); }, { once: true }); </script>
Related
- Reported by the Core Web Vitals check
- Make the largest element on the page load faster
- Make the largest element on the page load faster
- Stop the page layout from jumping while it loads
- Stop the page layout from jumping while it loads
- Make the page respond faster to clicks and taps
- Make the page respond faster to clicks and taps
- Reduce the JavaScript that blocks the page while it loads
- Collect real-user speed data for your site
Scan your domain to see whether this applies to you.