Home » Speed & Mobile » Third-Party Scripts and Widgets Breaking or Slowing Your Site
Third-Party Scripts and Widgets Breaking or Slowing Your Site
Most websites load code from other companies: analytics, ad networks, chat widgets, cookie banners, maps, video embeds, social buttons, review badges, font services. Each one is a small program you did not write, served from a server you do not control, that can change at any time.
When they behave, they add features. When they do not, they slow every page, throw errors that stop your own scripts, shift the layout, or simply fail to appear.
How third-party code causes problems
| Problem | What it looks like |
|---|---|
| Blocking load | Page stays blank until a slow external script finishes |
| Heavy JavaScript | Page loads but is sluggish to scroll and tap |
| Layout shift | Content jumps when an ad or widget appears |
| Script error | A widget, slider or form stops working |
| Outage at the provider | Missing chat button, blank map, broken page |
| Blocked by ad blockers or consent | Feature missing for some visitors only |
| Mixed content | HTTP embed blocked on an HTTPS page |
Step 1: take an inventory
List every external script and embed on the site. In DevTools:
- Open the Network tab and reload.
- Use the filter box with
-domain:yourdomain.com(Chrome) to hide your own files. - Note each domain and what it is for.
Then ask of each one: is it still used, and is it worth the cost? Old tracking pixels, abandoned A/B testing tools and duplicate analytics tags are common.
Step 2: measure the cost
PageSpeed Insights shows "Reduce the impact of third-party code" with time spent per provider. The Performance panel in DevTools shows long tasks and which script caused them. A chat widget that adds 500 KB of JavaScript to every page is a candidate for loading later.
Step 3: check for errors
Open the Console on key pages. Red errors from external domains can stop other scripts on the page if they run in the same block of code. Note:
Failed to load resource→ blocked, removed or down at the provider.... is not defined→ your code is calling a library that did not load.Refused to load ... Content Security Policy→ your security headers block it; allow the domain if you trust it.
Step 4: load scripts without blocking the page
- Add
async(for independent scripts like analytics) ordefer(for scripts that need the page to be parsed):
<script src="https://analytics.example/script.js" async></script>
- Load heavy widgets on interaction: show a static "Chat with us" button that loads the real chat script only when clicked.
- Replace video embeds with a thumbnail that loads the player on click ("lite" embeds).
- Lazy-load maps and iframes below the first screen with
loading="lazy". - Reserve space for ads and widgets with a fixed
min-heightso content does not jump.
Step 5: make failures harmless
Your site should still work when a third party does not:
- Do not let core features (navigation, forms, checkout) depend on optional scripts.
- Wrap your own code that calls third-party libraries in checks:
if (window.Analytics) window.Analytics.track('signup');
- Load scripts that track or set cookies only after consent, through your cookie banner.
Step 6: review regularly
Providers change their code without telling you. Check the Console and PageSpeed results every month or two, and after adding any new tool. Remove anything nobody uses.
Common mistakes
- Adding the same analytics tag twice (once in the theme, once in a plugin).
- Loading every widget on every page instead of only where it is needed.
- Pasting embed codes that use
http://on an HTTPS site. - Calling a third-party function without checking it loaded, which breaks your own scripts when the provider is blocked.
Frequently Asked Questions
How do I know which script is slowing my site?
Run PageSpeed Insights and look at 'Reduce the impact of third-party code', which lists each provider and the time it blocked the page. The DevTools Performance panel shows the same in more detail.
Why does a widget work for me but not for some visitors?
Ad blockers and privacy browsers block many analytics, ad and chat scripts. If your page relies on one of them to work, it will break for those visitors. Make sure core features do not depend on optional scripts.
Do I need consent before loading third-party scripts?
In many regions, scripts that set cookies or track visitors (analytics, ads, some embeds) need consent first. Load them only after the visitor agrees, through your cookie banner.
Found a mistake or still stuck? Contact us. See how we write and check these guides in our editorial policy, or read about DocumentGuy.