Third-party scripts and your page speed

Third-party JavaScript is code embedded in your page that you did not author and that is served from someone else's servers. Social sharing buttons, video embeds, chat widgets, advertising iframes, analytics, A/B testing tools, and helper libraries such as date formatters or animation utilities all fall into this category.

These scripts add real functionality, but they also bring costs in privacy, security, and page behavior. Above all, they can be a serious drag on performance.

Why third-party code hurts performance

A large amount of any JavaScript will slow a page down. But since you do not control third-party code, the problems can go beyond simple execution time.

Extra network traffic

Every server connection takes time to establish, especially secure ones that may require DNS lookups, redirects, and multiple round trips. Third-party scripts often make this worse by:

  • Triggering additional network requests
  • Loading unoptimized images and videos
  • Skipping proper HTTP caching, so resources are fetched repeatedly
  • Failing to compress resources at the server
  • Bundling duplicate copies of common frameworks and libraries

Render-blocking behavior

How a script is loaded matters. Synchronous third-party scripts sitting in the critical rendering path will delay parsing of the rest of the document. And if the third-party server fails, the page stops rendering until the request times out, which can take anywhere from 10 to 80 seconds. You can simulate this failure mode with WebPageTest's Single-Point-of-Failure tests.

Keeping third-party code in check

Eliminating third-party scripts is often not an option, but you can limit the damage:

  • Pick vendors that deliver the smallest amount of code required for the functionality you need.
  • Set performance budgets that account for third-party content.
  • Avoid duplication, such as running two tag managers or two analytics platforms for the same job.
  • Review your scripts periodically and remove any that are redundant or no longer used.

For a deeper look at auditing and efficiently loading your third-party resources, see the other guides in the Optimize your third-party resources section.