WhollySoftware
Back to blogWeb

Third-Party Script Management: Analytics, Chat Widgets, and Page Speed

Wholly Software TeamApril 21, 20257 min read
Third-Party Script Management: Analytics, Chat Widgets, and Page Speed

An audit for a mid-market SaaS client turned up fourteen separate third-party scripts on their marketing site: two analytics tools, a chat widget, a session recording tool, three ad pixels, an A/B testing platform, and several others accumulated over years of marketing team requests. Combined, they added 2.1 seconds to Time to Interactive and roughly 340KB of additional JavaScript, and nobody on the current team could say for certain which ones were still actively used.

Our first move wasn't deleting scripts — it was auditing usage with the marketing team, since 'we might need it later' isn't a technical argument we can win against. Two scripts turned out to be genuinely dead (an old heatmap tool replaced a year prior but never removed), and those came out immediately with no pushback once we showed the data.

For the rest, loading strategy mattered more than script count. Chat widgets and session recording tools don't need to block initial render, so we moved them to load after the page's main content was interactive, using Next.js's Script component with strategy="lazyOnload" for anything not needed for the first interaction. The chat widget specifically was deferred until either 3 seconds had passed or the user scrolled, whichever came first, since almost nobody engages chat in the first few seconds anyway.

Ad pixels and analytics needed to fire reliably for attribution, so those couldn't be arbitrarily delayed, but we did move them off the main thread where possible using Partytown, which runs third-party scripts in a Web Worker via a proxy and kept them from competing with the main thread for parse and execution time.

We also set up a lightweight budget check in CI — a Lighthouse CI run on every PR that fails the build if total third-party script weight exceeds a set threshold, currently 250KB. That's caught two attempts to add new tracking scripts without a conversation about the trade-off, which is really the point: it forces the cost to be visible before it ships, not discovered in a quarterly audit.

After the changes, Time to Interactive dropped from 2.1 seconds of third-party overhead to about 400ms of unavoidable, necessary overhead, and the marketing team kept every tool they actually used.

Web PerformanceThird-Party ScriptsAnalyticsLighthouse
Third-Party Script Management: Analytics, Chat Widgets, and Page Speed — Wholly Software