{"id":356,"slug":"rule-defer-third-party-scripts-until-interaction","title":"RULE: Defer or delay every third-party script until user interaction, except those required for first paint","kind":"rule","scope":"business","status":"current","audiences":["claude-code","dev","candid-team"],"topics":["core-web-vitals","agency-methodology"],"reference_body":"**Rule:** Every third-party script on a Candid Creative client site is **deferred or delayed until first user interaction**, except those genuinely required for first paint (which should be rare). Default loading strategy: `strategy=\"lazyOnload\"` (Next.js) or Partytown / web-worker isolation.\n\n**Why:** Third-party JavaScript is the single largest avoidable INP cost (see [[inp-killers-catalogue]]). A GTM container with 18 tags increases TBT ~20× ([[gtm-18-tags-20x-tbt-chrome-aurora]]). Most SMB sites accumulate 8-15 third-party scripts over 2-3 years without auditing the cumulative cost.\n\n**How to apply:**\n- Inventory third-party scripts at engagement onboarding; rank by ROI\n- For Next.js: `next/script` with `strategy=\"lazyOnload\"` for analytics, chat, A/B testing, heatmaps\n- For others: Partytown to move 3rd-party JS to a web worker\n- Anti-flicker holds on A/B testing tools (Optimizely, VWO) cost both LCP and INP — re-evaluate quarterly whether the test is worth the perf penalty\n- Chat widgets (Intercom, Drift, HubSpot): only load on click of a chat trigger, never on page load\n- One-script-in, one-out rule: net script count never grows without explicit justification\n\nPairs with [[rule-enforce-performance-budgets-in-ci]] for governance.","rationale_body":null,"metadata":null,"links":{"outgoing":[{"slug":"gtm-18-tags-20x-tbt-chrome-aurora","title":"Chrome Aurora team: Google Tag Manager with 18 tags increases Total Blocking Time ~20×","kind":"reference","scope":"business","link_type":"depends-on"},{"slug":"inp-killers-catalogue","title":"Reference: the 8 most common INP killers — ranked by observed frequency","kind":"reference","scope":"business","link_type":"depends-on"}],"incoming":[{"slug":"research-brief-page-speed-moat","title":"Research brief: Page Speed as a Moat — why CWV separates the agencies from the freelancers (piece 9 of 15)","kind":"reference","scope":"business","link_type":"relates-to"}]},"created_at":"2026-05-22T20:03:33.400Z","updated_at":"2026-05-22T20:03:33.400Z"}