Third-party scripts blocking interactions: diagnosing and containing them
What is happening
Third-party scripts — analytics, tag managers, ads, chat widgets, A/B testing — run on the same main thread as your code. When a tag manager evaluates fifty rules or an ad script parses a payload, your user's click waits exactly like it would for your own long task.
The Long Animation Frames API attributes long tasks to their source URL, so you can see exactly which domain is costing you INP.
How to recognise it
- Long tasks in DevTools Performance are attributed to external domains (googletagmanager.com, connect.facebook.net, widget CDNs).
- INP got worse after adding a marketing tag, with no changes to your own code.
- Input delay spikes shortly after load, when third-party scripts initialise.
How to fix it
- Load every third-party script with async or defer; never synchronously in <head>.
- Audit the tag list: remove tags nobody uses — deleting a script is the only fix that costs zero milliseconds.
- Move tags off the main thread with Partytown (runs them in a Web Worker), and load widgets like chat on user intent (first click) instead of page load.
Problem
<script src="https://cdn.example-widget.com/loader.js"></script>
<!-- synchronous: blocks parsing AND competes for the main thread -->
Fix
<script async src="https://cdn.example-widget.com/loader.js"></script>
<!-- or better: inject on first user intent -->
<script>
chatButton.addEventListener("click", loadChatWidget, { once: true })
</script>
Scan your site for free →