01 — Purpose

External scripts, your user experience

Third-party scripts often create major performance problems — every external dependency should justify its cost.

Analytics, chat widgets, A/B tools, ad tags, and social embeds run in your origin’s context. Their bytes, blocking behaviour, and layout impact are yours to manage — even when you did not write the code.

See the third-party embeds pattern and JavaScript cost for related guidance.

02 — Principles

Justify every dependency

External scripts still affect your user experience — own the responsibility.

  • audit dependencies regularly — remove what no longer earns its place
  • measure impact continuously — before and after adding each script
  • lazy load where possible — defer non-critical tags until after first paint
  • reduce unnecessary embeds — one analytics stack, not three

03 — Practice

Common problems and good practice

Render blocking, excessive payloads, layout shifts, and tracking overhead.

  • load tags async or defer — avoid render-blocking third-party JS in head
  • reserve space for embeds and ad slots — prevent CLS when content injects
  • use a tag manager with discipline — not an excuse to add everything
  • self-host or proxy where feasible — fewer DNS lookups and connection chains
  • document owners, purpose, and removal criteria for each vendor script

04 — Avoid

Third-party debt

Scripts accumulate silently until pages feel sluggish for everyone.

  • render-blocking analytics or chat in the critical path
  • excessive JS payloads — multiple trackers, heatmaps, and widgets stacked
  • layout shifts from late-loading embeds without reserved dimensions
  • tracking overhead on every interaction — main-thread work from observers
  • adding vendors without measuring LCP, INP, or error rate impact

05 — Close

Your page, your performance budget

Treat third-party scripts like first-party code in review.

Before adding a vendor, record baseline CWV and bundle weight. After integration, measure again. If the cost is too high, negotiate async loading, remove duplicates, or find a lighter alternative.

See third-party embeds, JavaScript cost, and performance monitoring.