JavaScript cost and the main thread · senior
Third-party scripts: cost, loading and governance
Tag managers, analytics, chat widgets, A/B testing and ads often cost more main-thread time than your own code, so you inventory them, load them late (defer, after consent, on interaction, via a facade), and own a budget and a review process for new tags.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Third parties hurt every vital: they compete for bandwidth (LCP), run long tasks (INP via input delay), and inject content (CLS).
- Inventory: use the DevTools third-parties insight / Network panel grouped by domain; measure main-thread time per domain.
- Load strategies: defer or async; load after the page is interactive or after consent; load on interaction (a facade: show a static image of the chat button and load the real widget on click).
- Client-side A/B testing that hides the page until the experiment loads ('anti-flicker') delays LCP; prefer server-side or edge experiments.
- Security and privacy overlap: third-party scripts run with full page access; limit them with CSP and SRI where possible.
- Governance: a performance budget per page, an owner for every tag, a review before adding tags, and periodic removal of unused ones.
The red pen
Common traps: mistake → fix
Mistake: "async scripts don't block anything"
Fix: async avoids parser blocking, but the script still runs long tasks on the main thread when it arrives.
Mistake: "It's a third-party, we can't do anything"
Fix: you control when and whether it loads, and you can use facades or server-side alternatives.
Mistake: "A tag manager makes scripts faster"
Fix: it makes them easier to add, which often adds more cost.
Easy to hard
Questions interviewers ask, easy to hard
- How do third-party scripts affect Core Web Vitals?
- How would you load a chat widget without hurting INP?
- Marketing wants to add five new tags before Diwali. How do you handle it?
- How do you make performance a shared responsibility with non-engineering teams?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.