Check 06.14 · Performance and Core Web Vitals

Limit third-party scripts

Inventory third-party scripts, remove the useless ones and load the rest at lower cost: facades, Zaraz, Partytown, settings by CMS and framework.

Priority
Important
Difficulty
Intermediate
Estimated time
2 h to 1 day
Free, no account: your progress is saved in this browser.

Ask an AI to check this point on your site

Opens the assistant with a ready-made question: this check, its goal and your site URL.

For Gemini, Copilot or another assistant, copy the question. The link opens the chosen service directly: nothing goes through this site.

In short

A third-party script is a script served from a domain you do not control: analytics, advertising, chat, reviews, A/B tests, embedded videos and maps, share buttons. Limiting third-party scripts means keeping an inventory of them, removing those that are no longer used and loading the others in a way that does not penalize display or responsiveness. The expected result: every third-party script has an owner, a reason to exist and a deliberately chosen loading method.

Why it matters

A third-party script costs more than a first-party script of the same size:

  • Extra connection: DNS resolution, TCP connection and TLS negotiation with a new domain, before even the first byte.
  • Weight and execution beyond your control: the vendor can make its script heavier overnight. The code runs on your page's main thread, competing with your own scripts.
  • Chained loading: a tag manager loads tags, which load other scripts. The HTML shows only a small part of them.
  • Dependency: a slow or failing third party can delay the page if it is loaded in a blocking way.
  • Personal data: many of these scripts set trackers that require consent. See handle applicable consent requirements (opens in a new tab).

These scripts pile up because nobody removes them: a campaign that has ended, an abandoned tool, an uninstalled plugin whose code stayed in the theme. A regular inventory is often the most cost-effective performance gain on a marketing or e-commerce site.

What it improves

  • INP (Interaction to Next Paint, the responsiveness to interactions): this is the first benefit. Less third-party JavaScript means fewer long tasks delaying the response to clicks.
  • LCP (Largest Contentful Paint, the display of the largest visible element): less competition for the network and the CPU during loading.
  • CLS (Cumulative Layout Shift, layout shifts): fewer banners, widgets and ads injected late.
  • Reliability and security Fewer external dependencies, a smaller attack surface.
  • Compliance An up-to-date inventory makes it easier to maintain the register of trackers.
  • Rankings Indirect effect, through Core Web Vitals.

How to check

Count the third-party domains. In the browser console, once the page has fully loaded:

const hosts = {};

performance.getEntriesByType('resource').forEach((entry) => {
  const host = new URL(entry.name).hostname;

  if (host === location.hostname) {
    return;
  }

  hosts[host] = (hosts[host] || 0) + 1;
});

console.table(hosts);

You get the number of requests per third-party domain. For weight, use the Network tab: More filters > 3rd-party requests, then sort by size.

Measure the cost. PageSpeed Insights and Lighthouse list third parties with their transfer size and main-thread time in the audit on third-party code. See analyze PageSpeed Insights and Lighthouse (opens in a new tab).

Measure the effect of removing one. In Chrome's developer tools, open the network request blocking panel (Ctrl+Shift+P, then “block”), add the third party's domain, reload and run Lighthouse again. The difference in Total Blocking Time gives the order of magnitude of the gain.

Compliant result: every third-party domain in the list matches a line in your inventory, and none is loaded by a blocking tag in the <head>.

Good to know: lab tests usually stop at the consent banner. Scripts triggered after acceptance do not show up: see test before and after cookie consent (opens in a new tab).

How to implement

Step 1 — Build the inventory

A shared spreadsheet is enough. Columns to include:

Script Domain Purpose Owner Pages concerned Loaded by Decision
Live chat widget.example.net Support Customer service All Template Load on click
Summer campaign pixel px.example.org Advertising Marketing All Tag manager Remove
Customer reviews avis.example.net Reassurance E-commerce Product pages Plugin Load on visibility

For each line, only one decision is possible: remove, replace (with a self-hosted or lighter version), delay or keep as is. A script with no identified owner gets removed.

Step 2 — Apply the right technique

  • Restrict to the pages that need it: the payment script on the checkout funnel, the map on the contact page, not across the whole site.
  • Facade: display a clickable image in place of the video player, the map or the chat, and load the third party only on click.
  • Self-hosting: serve fonts and open-source libraries from your own domain. Browsers partition their cache by site: a file already downloaded from a public CDN on another site is not reused on yours.
  • Late loading: async at a minimum, loading on idle or on visibility for the rest. See defer non-essential scripts (opens in a new tab).
  • Preconnect for the rare third parties that are essential early on: <link rel="preconnect" href="https://cdn.example.net">.

A facade for a YouTube video, which works even without JavaScript (the link opens the video):

<a class="video-facade" href="https://www.youtube.com/watch?v=VIDEO_ID" data-video-id="VIDEO_ID">
  <img src="/images/video-cover.jpg" width="1280" height="720" alt="Product demo" loading="lazy">
  <span>Play the video</span>
</a>

<script>
  document.querySelectorAll('.video-facade').forEach(function (link) {
    link.addEventListener('click', function (event) {
      event.preventDefault();

      var iframe = document.createElement('iframe');
      iframe.src = 'https://www.youtube-nocookie.com/embed/' + link.dataset.videoId + '?autoplay=1';
      iframe.width = 1280;
      iframe.height = 720;
      iframe.title = link.querySelector('img').alt;
      iframe.allow = 'autoplay; encrypted-media; picture-in-picture';
      iframe.allowFullscreen = true;

      link.replaceWith(iframe);
    });
  });
</script>

Step 3 — Clean up the tag manager

In Google Tag Manager, open Tags and sort by last edited date. Delete paused tags and those of campaigns that have ended, replace “All Pages” triggers with targeted triggers, and review every “Custom HTML” tag: these are the ones that inject scripts without any control. Publish a new version and record it in the inventory. See set up Google Tag Manager if needed (opens in a new tab).

Cloudflare

Versions Cloudflare dashboard, Zaraz, all plans, November 2026.

Zaraz runs compatible third-party tools on Cloudflare's network rather than in the browser: the page no longer loads the vendor's script. In the dashboard, open Zaraz's “Tag Setup” page, then Third-party tools > Add new tool, choose the tool from the catalog, enter its ID and triggers, then save. Then remove the original tag from the site so that nothing is counted twice.

Zaraz has its own consent management: configure it before adding a tool that requires consent. Billing depends on the number of events: check the terms of your plan in the documentation.

WordPress

Versions WordPress 6.0 to 7.1; Query Monitor, Perfmatters, Asset CleanUp and WP Rocket in their November 2026 versions; LiteSpeed Cache 7.x.

Every plugin can add its own third-party scripts. Method:

  1. Install Query Monitor, open a public page while logged in and look at the Scripts panel: it lists each script with its host and path. The wp-content/plugins/… folder points to the plugin responsible, and the host column makes third-party domains stand out.
  2. Deactivate, then delete, the plugins you no longer use. See remove unnecessary plugins (opens in a new tab).
  3. For a plugin that is only useful on a few pages, remove its scripts everywhere else:
add_action('wp_enqueue_scripts', function (): void {
    if (is_page('contact')) {
        return;
    }

    wp_dequeue_script('handle-du-formulaire');
    wp_dequeue_style('handle-du-formulaire');
}, 100);

The Perfmatters (Script Manager) and Asset CleanUp plugins do the same thing from the interface, page by page. WP Rocket and LiteSpeed Cache offer to replace YouTube iframes with a preview image: enable this option if you embed videos.

Shopify

Versions Shopify admin, all plans, November 2026.

  • Apps: Settings > Apps and sales channels. Uninstall those you no longer use, then look in layout/theme.liquid and in the snippets folder for any code they may have left behind: uninstalling does not always clean up the theme.
  • App embeds: Online Store > Themes > Customize > App embeds. Disable the blocks you do not need.
  • Pixels: move tracking pixels pasted into the theme to Settings > Customer events. Pixels there run in a sandbox isolated from the page, which reduces their effect on the main thread, and they respect the store's privacy settings.

PrestaShop

Versions PrestaShop 8 and 9.

Open Design > Positions and look at which modules are hooked to displayHeader, displayAfterBodyOpeningTag and displayBeforeBodyClosingTag: these are the ones that inject scripts. Disable or uninstall unnecessary modules in Modules > Module Manager, then clear the cache in Advanced Parameters > Performance.

Magento

Versions Adobe Commerce and Magento Open Source 2.4.x (up to 2.4.9).

List the enabled modules and disable those you do not use:

bin/magento module:status
bin/magento module:disable Vendor_Module
bin/magento setup:upgrade
bin/magento cache:flush

The modules' etc/csp_whitelist.xml files provide a useful inventory of the third-party domains allowed by the Content Security Policy. In Content > Design > Configuration, the “Scripts and Style Sheets” field (HTML Head section) and the “Miscellaneous HTML” field (Footer section) often contain forgotten scripts.

Drupal

Versions Drupal 10 and 11.

Third-party scripts come from contributed modules (Google Tag, chat or advertising integrations) or from libraries declared with type: external in a *.libraries.yml file. Uninstall unnecessary modules in Extend > Uninstall and restrict the others by path or by role in their settings.

Wix

Versions Wix dashboard, premium plans with a connected domain, November 2026.

Inventory Settings > Custom Code and the marketing integrations: delete unnecessary snippets and restrict the others to the pages concerned (page targeting option).

Squarespace

Versions Squarespace 7.1, Core plans and above, November 2026.

Review the site-wide Code Injection and the one on each page, as well as the connected extensions. Remove anything that no longer has a use.

Webflow

Versions Webflow, paid site plans, November 2026.

Review Site settings > Custom code, each page's custom code and the integrations in the Apps & Integrations tab.

Laravel

Versions Laravel 10 to 13.

Load third parties only in production and on the templates that need them:

@production
    @if(request()->routeIs('contact.*'))
        <script src="https://widget.example.net/loader.js" async></script>
    @endif
@endproduction

Centralize the IDs in config/services.php to keep a readable inventory in the code.

Symfony

Versions Symfony 6.4, 7.4 and 8.x, with Twig.

Same principle in Twig:

{% if app.environment == 'prod' and app.request.attributes.get('_route') starts with 'contact_' %}
    <script src="https://widget.example.net/loader.js" async></script>
{% endif %}

Next.js

Versions Next.js 15 and 16 (App Router); @next/third-parties package, still experimental.

The @next/third-parties package, still described as experimental by Next.js, provides optimized components for common third parties:

import { GoogleTagManager } from '@next/third-parties/google';

export default function RootLayout({ children }) {
  return (
    <html lang="fr">
      <GoogleTagManager gtmId="GTM-XXXXXXX" />
      <body>{children}</body>
    </html>
  );
}

YouTubeEmbed and GoogleMapsEmbed, from the same package, load a lighter or lazy version of the embed. For other third parties, use next/script with strategy="lazyOnload". Only render a component that requires consent once consent has been given.

Nuxt

Versions Nuxt 3.16 and later and Nuxt 4; Nuxt Scripts module 1.x.

The Nuxt Scripts module offers a registry of third parties (analytics, videos, maps, chat) with deferred loading and facade components. Refer to its registry for the exact names of the composables:

useScript('https://widget.example.net/loader.js', {
  trigger: useScriptTriggerIdleTimeout({ timeout: 5000 }),
});

Astro

Versions Astro 5 to 7; @astrojs/partytown integration 2.x.

The Partytown integration moves third-party scripts into a web worker, off the main thread:

npx astro add partytown
// astro.config.mjs
import { defineConfig } from 'astro/config';
import partytown from '@astrojs/partytown';

export default defineConfig({
  integrations: [
    partytown({ config: { forward: ['dataLayer.push'] } }),
  ],
});
<script type="text/partytown" src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX"></script>

Warning: not every script works in a worker (synchronous DOM access, iframes, some A/B testing tools). Check in the tool itself that data is still coming in after the switch.

Common mistakes

  • Uninstalling an app without cleaning up the theme: the script stays in the template and sometimes points to an abandoned domain.
  • Loading a third party synchronously in the <head>: if its server is slow, the whole page waits.
  • Stacking redundant tools: two analytics solutions, three pixels for the same ad network, two session recording tools.
  • Assuming the tag manager is free in performance terms: its container grows with every tag, and Custom HTML tags inject whatever they like.
  • Adding too many preconnect hints: beyond a few truly critical domains, they use up connections for nothing.
  • Loading a script that requires consent before consent is given, on the grounds that it has been “optimized”: moving it into a worker or to the server side does not exempt it from consent.
  • Doing the inventory only once: schedule a quarterly review and add the number of third-party requests to your performance budget (opens in a new tab).

Frequently asked questions

How do I find out which third-party scripts slow down my site?

Run PageSpeed Insights or Lighthouse: the audit on third-party code lists each provider with its transfer size and main-thread time. To measure the effect of removing one, block the third party's domain in Chrome's developer tools, reload and run Lighthouse again: the difference in Total Blocking Time gives the order of magnitude of the gain. Also test after accepting cookies.

Does Google Tag Manager slow down the site?

It can. The container grows with every tag, and Custom HTML tags inject scripts without any control, which sometimes load others in a chain. Delete paused tags and those of campaigns that have ended, replace “All Pages” triggers with targeted triggers, and review every Custom HTML tag before publishing a new version of the container.

What is a facade for a YouTube video?

A facade is a clickable image displayed in place of the video player, the map or the chat: the third-party script only loads when the visitor clicks. For YouTube, a link to the video with its thumbnail is enough, replaced on click by the player iframe. The page no longer downloads the player at load time, which relieves the network and the main thread.

Updated on

Topic checklist (PDF)

And now?

In the “Performance and Core Web Vitals” topic

  1. Analyze PageSpeed Insights and Lighthouse
  2. Analyze real-user CrUX data
  3. Target LCP ≤ 2.5 s at the 75th percentile
  4. Target INP ≤ 200 ms at the 75th percentile
  5. Target CLS ≤ 0.1 at the 75th percentile
  6. Target TTFB ≤ 800 ms as a benchmark
  7. Optimize hosting and CDN
  8. Enable Brotli/Gzip
  9. Configure browser and server caching
  10. Minify CSS and JavaScript
  11. Remove unused CSS/JS
  12. Reduce render-blocking resources
  13. Defer non-essential scripts
  14. Limit third-party scripts
  15. Optimize database queries
  16. Optimize fonts (WOFF2, font-display)
  17. Preload only critical resources
  18. Optimize the LCP image without lazy loading
  19. Lazy-load offscreen content
  20. Reserve space for media and ads
  21. Reduce DOM complexity
  22. Test before and after cookie consent
  23. Test on a slow mobile connection
  24. Set a performance budget
  25. Preload likely navigations with Speculation Rules
  26. Make pages eligible for the back/forward cache (bfcache)
  27. Diagnose INP with Long Animation Frames (LoAF)