JavaScript 3 min read

Third-Party Scripts: How to Stop Them Slowing Your Site

Analytics, ads, chat widgets, pixels and embeds can quietly outweigh your entire website. Learn to audit third-party scripts, cut the waste and load what's left without hurting speed.

On this page

Key takeaways

  • Third-party scripts — analytics, ads, chat, heatmaps, social widgets — are often the biggest cause of poor INP and slow loads.
  • Audit them regularly: remove what nobody uses, delay what isn’t critical, and lazy-load embeds.
  • Self-host or proxy where possible, and keep everything under one tag manager with clear ownership.

Your own code might be lean, but the moment marketing adds a pixel, a heatmap, a chat widget and two A/B testing tools, the page can double in weight. Each vendor’s script runs on your visitors’ phones, competes for the main thread and can break when the vendor has an outage. Here’s how to keep them under control.

Step 1: inventory every third party#

  1. Run PageSpeed Insights and open “Reduce the impact of third-party code” — it lists each provider’s transfer size and main-thread time.
  2. In DevTools → Network, filter by domain to see every external request.
  3. Export all tags from Google Tag Manager.
  4. For each, record: owner, purpose, last time anyone used the data, pages it’s needed on.

Step 2: remove, replace or reduce#

Script Typical fix
Unused pixels from old campaigns Remove
Two analytics tools doing the same job Keep one
Heatmap / session recording Run only during research periods, on selected pages
Chat widget Load on interaction, or use a lightweight built-in assistant
Social feed widgets Replace with static links or periodic screenshots
YouTube / Maps embeds Facades — see embeds guide
Font services Self-host — see web fonts guide

This site’s assistant, Ask Ifti, is built into the theme and loads with a small deferred script instead of a third-party chat platform, for exactly this reason.

Need a hand with this?

Get a quick, honest review of your website’s SEO.

Chat on WhatsApp

Step 3: control how the rest load#

  • async/defer for every external script — see defer vs async.
  • Delay until interaction for non-critical tags (chat, heatmaps, social pixels).
  • Load per page: booking widgets only on booking pages; e-commerce pixels only where needed.
  • Preconnect only to the one or two most critical third-party origins.
  • Tag Manager hygiene: trigger tags on specific events/pages, not “All pages” by default.

Advanced options#

  • Server-side tagging (server-side GTM) moves vendor processing off the visitor’s device.
  • Partytown runs some third-party scripts in a web worker, off the main thread.
  • Consent mode avoids loading marketing tags until visitors agree, which also helps privacy compliance.

Reliability and security#

  • A slow vendor shouldn’t block your page — never load third-party scripts synchronously in the head.
  • Use Subresource Integrity (integrity) for static library files from CDNs.
  • Consider a Content Security Policy listing allowed script sources.
  • Review new tag requests: who needs it, for how long, and what data it collects.

Third-party scripts FAQ#

Does Google Analytics slow my site?#

GA4 loaded asynchronously has a modest impact. The bigger problems are usually many tags stacked together.

Is Google Tag Manager bad for performance?#

GTM itself is reasonable; what you put inside it determines the cost. Audit and trim the tags.

How do third-party scripts affect Core Web Vitals?#

They mostly hurt INP (main-thread work) and sometimes LCP (bandwidth competition) and CLS (injected widgets).

Found this useful? Share it

Join the discussion

Your email address will not be published. Required fields are marked *

Security code image. If you cannot read it, press refresh or contact me on WhatsApp.