Cozmo Scan My SEO Logo

Managing Third-Party Scripts for a Faster, Cleaner Website


Run a Crawl Now

Third-Party Scripts Should Earn Their Place

Third-party scripts add features that many websites depend on: analytics, advertising, consent tools, chat, reviews, maps, video players, payment services, social embeds, and A/B testing. The trade-off is that each provider can add network requests, JavaScript execution, layout changes, and dependencies on systems you do not control.

The right response is not to remove every external script or add async to every tag. Start by finding what each script does, who owns it, where it loads, what business value it provides, and what performance cost it creates. Then choose the least disruptive treatment: remove it, restrict it to relevant pages, delay it, lazy-load it, replace it, or keep it and monitor it.

Performance tools often call a resource “third-party” when it comes from a different origin—usually another domain—than the page. That is useful for measurement, but it is not the whole governance picture. A vendor library that you self-host may look first-party in a network report while still leaving you responsible for the vendor’s updates, security notices, and behaviour.

Choose the Treatment Before You Touch the Code

Use this decision order for each script or embed:

  • No clear owner, purpose, or current use: verify that nothing depends on it, then remove it.
  • Needed only on certain pages: stop loading it sitewide and restrict it to the templates or journeys that use it.
  • Needed only after consent, interaction, or scrolling: load it only when that condition is met.
  • Independent and safe to run as soon as it arrives: use the vendor-supported asynchronous loading method.
  • Dependent on the document or execution order: use an ordered deferred strategy, following the vendor’s documentation.
  • A heavy offscreen embed: lazy-load it or replace it with a lightweight, click-to-load preview.
  • Business-critical but expensive: configure a lighter version, narrow its scope, or compare alternative providers.
  • Useful and proportionate: keep it, assign an owner, and monitor it for regressions.

The highest-priority candidates are normally scripts with high user cost and low proven value. Removing one redundant tag often saves more than several small loading tweaks combined.

How Third-Party Code Slows a Page

It competes for network capacity

A single vendor tag may open connections to several domains and then request more JavaScript, images, fonts, pixels, or iframes. Those requests can compete with your own page content, particularly on slower mobile connections. The visible script file is therefore not always the full cost; inspect the requests it initiates as well.

It adds work to the browser’s main thread

Downloading JavaScript is only one part of the cost. The browser must parse, compile, and execute it on its main thread, which handles much of the page’s rendering and response to user input. Long tasks can delay clicks, taps, and keyboard input, which may worsen Interaction to Next Paint (INP). In lab tests, Total Blocking Time (TBT) can help identify main-thread blocking during page load, but it is a diagnostic metric rather than a field Core Web Vital.

It can delay visible content

A classic script without a suitable loading strategy can pause HTML parsing while it is fetched and executed. Even an asynchronously downloaded script still occupies the main thread while it runs. Third-party code can also compete with the page’s main image, font, or stylesheet and indirectly delay Largest Contentful Paint (LCP), which measures when the main visible content appears.

It can create layout shifts

Ads, review widgets, chat launchers, maps, and video embeds may inject content after the surrounding page has rendered. If the page has not reserved enough space, nearby content can move, contributing to Cumulative Layout Shift (CLS). Loading an embed later is only a complete fix when its placeholder also has stable dimensions.

It changes outside your release process

A provider can increase its payload, alter its subrequests, fail, or introduce a new dependency without a deployment from your team. This is why a script that was acceptable six months ago may now need attention even when your own code has not changed.

These effects matter to users first. Google states that Core Web Vitals are used by its ranking systems, but good scores do not guarantee high rankings and page experience is broader than any single metric. Treat third-party optimisation as user-experience and operational work, with search visibility as one possible benefit rather than a promised outcome. See Google Search Central’s page experience guidance.

Audit the Scripts Before You Change Them

A useful audit connects technical cost to business purpose. Do not begin with a list of file sizes and assume the largest file should go.

Do not treat the mere presence of third-party requests as an automatic failure. Chrome’s current Third parties performance insight lists detected providers for investigation; the decision still depends on their cost, timing, and purpose.

  1. Select representative pages and states.

    Test the homepage and the main page templates that matter to the business, such as product, category, article, lead-generation, account, and checkout pages. Include mobile conditions, logged-in and logged-out states, and the relevant consent choices. A script may load only after an interaction or only for a particular audience.

  2. Create a script register.

    For every provider, record the owner, purpose, pages, trigger, vendor account, business metric, where data is sent, dependencies, and review date. Include tags injected through a tag manager and resources spawned by other scripts. “Nobody knows” is a reason to investigate, not automatic proof that removal is safe.

  3. Inspect the network waterfall.

    Chrome DevTools can filter the Network panel to show only third-party requests. Sort by transfer size, duration, or start time, then inspect the Initiator information to discover which tag caused each request. The official Chrome Network panel reference also explains request filtering and blocking.

  4. Record main-thread activity.

    Use the Performance panel while loading the page and completing an important interaction. Chrome can distinguish first- and third-party activity and report transfer size and main-thread time by entity. This reveals vendors that look small in the Network panel but run expensive code. See the Chrome Performance panel reference.

  5. Use lab and field data for different jobs.

    Lab tests are useful for reproducing and debugging a problem under controlled conditions. Field data shows how real visitors experienced the page over time. Google’s PageSpeed Insights documentation explains that its Lighthouse data is diagnostic while Chrome User Experience Report data reflects real-user experience over a rolling period. Do not treat one Lighthouse run as proof of a lasting improvement.

  6. Simulate removal before deleting a business-critical tag.

    In a safe test environment, block a vendor’s requests and repeat the page load and user journey. Compare the trace, confirm what breaks, and check whether another tag replaces the same function. For analytics, advertising, consent, payment, or fraud-prevention tools, involve the owner before deployment.

A crawler can help you discover where scripts appear across page templates. Browser traces are still needed to understand execution cost, interaction delay, and the requests a tag creates after the page begins running.

Fix Third-Party Scripts in the Right Order

Work from structural savings to smaller delivery improvements. This prevents teams from polishing a script that should not have loaded in the first place.

  1. Remove duplicates, expired experiments, and abandoned tools.

    Check for analytics loaded both directly and through a tag manager, old chat or review widgets, inactive A/B tests, duplicate pixels, and plugins that inject tags after their visible feature has been disabled. Remove one item at a time and verify the associated journey and reporting.

  2. Restrict each script to the pages and conditions that need it.

    A booking widget may belong only on booking pages. A map may be required only on location pages. A campaign pixel may need a defined start and end date. Conditional loading reduces network and main-thread work without removing useful functionality.

  3. Choose async and defer by behaviour, not habit.

    For classic scripts, async downloads without blocking HTML parsing but executes as soon as the file is ready; execution order is not guaranteed. defer downloads in parallel, waits until the document has been parsed, and preserves order between deferred scripts. The MDN script element reference documents the distinction.

    
    <!-- Independent script: use only when the vendor supports this pattern. -->
    <script src="https://vendor.example/independent-tag.js" async></script>
    
    <!-- DOM- or order-dependent script. -->
    <script src="https://vendor.example/dom-dependent-widget.js" defer></script>
            

    Do not rewrite a vendor snippet blindly. Some loaders intentionally create additional scripts, and changing their order can break consent, attribution, personalisation, or the feature itself.

  4. Lazy-load offscreen embeds and reserve their space.

    Videos, maps, social feeds, and similar iframes that begin below the visible area are strong candidates for native lazy loading. Always provide meaningful titles and stable dimensions. Do not lazy-load the page’s primary content merely to improve a test score.

    
    <iframe
      src="https://embed.example/content"
      loading="lazy"
      width="560"
      height="315"
      title="Interactive content">
    </iframe>
            

    When most visitors do not use an embed, a static preview or click-to-load “facade” can avoid loading the provider until interaction. web.dev’s third-party embed guidance explains lazy loading, facades, and reserving space.

  5. Configure a lighter service or compare alternatives.

    Disable unused modules, animations, auto-opening behaviour, recordings, or integrations when the provider allows it. If the vendor remains disproportionately expensive, compare alternatives against the required feature set, data quality, accessibility, privacy, support, and migration cost—not performance alone.

  6. Use preconnect only for a small number of critical origins.

    Preconnect can start connection setup earlier, but every early connection consumes browser resources. Use it only when an important third-party request is definitely needed near the start of the page. MDN warns that preconnecting many domains can be counterproductive in its preconnect reference.

    
    <link rel="preconnect" href="https://cdn.example.com">
            
  7. Self-host only when you can own the consequences.

    Self-hosting a stable library can improve control over caching and delivery, but it also transfers responsibility for licensing, version updates, security patches, and compatibility. It may not work for dynamic vendor scripts, and an outdated local copy can be worse than the original. For a fixed, versioned resource whose provider supports the required cross-origin checks, Subresource Integrity can let the browser verify the expected file. A carefully tested Content Security Policy can also restrict which script sources a page may load.

Common “Fixes” That Often Backfire

  • Adding async to everything: dependent scripts can run out of order, and asynchronous execution can still interrupt rendering or interaction.
  • Using an arbitrary timeout: loading a widget five seconds later does not reduce its total cost and may move the interruption into the user’s first interaction.
  • Assuming a tag manager makes tags efficient: a tag manager centralises deployment, but it can also hide duplicated, expired, or over-broad triggers.
  • Preconnecting every vendor: speculative connections compete for sockets, memory, and processing. Prioritise only the few origins that are both early and important.
  • Self-hosting and then forgetting the file: local delivery is not a performance win if the script becomes insecure, incompatible, or permanently outdated.
  • Optimising only the homepage: script cost often differs by template, consent state, campaign, device, and logged-in status.
  • Chasing a perfect Lighthouse score: the objective is a faster, stable, functional journey for real users, not a cosmetic score increase.
  • Removing consent, payment, fraud, or measurement controls without review: performance work must not silently break legal obligations, revenue attribution, or critical customer journeys.

Worked Example: A Service Page With Four Vendors

This example is hypothetical. It demonstrates the decision process without claiming a guaranteed speed, conversion, or ranking result.

What the audit finds

A local service website loads an analytics tag directly in the template and again through its tag manager. A chat widget starts on every page, an interactive map loads below the fold, and an old A/B testing tag remains active even though the experiment ended months ago.

The Network panel shows the duplicate analytics requests and the additional domains opened by the chat and map. A Performance recording shows that the chat vendor performs noticeable main-thread work during page load. Request blocking confirms that the page’s core content and lead form still work without the expired experiment and duplicate tag.

What the team changes

  • Remove the hard-coded duplicate analytics tag after verifying that the tag-manager version records the required events.
  • Delete the expired experiment and document an expiry date for future campaign tags.
  • Load chat only on the contact and quote journeys, or after a clear user action.
  • Lazy-load the map and reserve its width and height so the page does not shift when it appears.
  • Keep the consent tool and essential analytics configuration, then test every consent state.

What the team verifies

They repeat the same lab tests, complete the lead journey, inspect analytics events, test mobile and desktop layouts, and monitor field data after release. The lesson is not that every website should remove chat or maps; it is that each vendor should load only where its value justifies its cost. For a more focused example, see ScanMySEO’s third-party scripts and Total Blocking Time before-and-after guide.

Verify the Fix Without Losing Data or Functionality

Third-party changes can make a synthetic test look better while silently damaging tracking, consent, payments, personalisation, or a later interaction. Use a defined before-and-after check.

  1. Keep the comparison fair: use the same URL, device profile, network conditions, consent state, and cache state; run several lab tests rather than selecting the best result.
  2. Retest key journeys: forms, checkout, login, media, maps, chat, advertising, account features, and any action tied to the changed provider.
  3. Validate data: confirm analytics events, conversions, consent behaviour, campaign parameters, and vendor dashboards.
  4. Compare technical evidence: third-party transfer size, request count, main-thread time, render-blocking behaviour, layout shifts, TBT in lab data, and the interactions most relevant to the page.
  5. Monitor field experience: allow for the reporting window and traffic requirements of field datasets, or use your own real-user monitoring for faster feedback.
  6. Watch for regression: record the script owner, approved loading conditions, agreed performance limit, and next review date so a vendor update or new tag does not undo the work.

For a fuller testing sequence, use ScanMySEO’s performance verification decision guide.

Quick Reference: Eight Questions for Every Third-Party Script

  • Owner: Who is accountable for this script and its vendor account?
  • Purpose: Which user or business task does it support?
  • Evidence: Is that value measured, current, and greater than the script’s cost?
  • Scope: Which pages, users, consent states, or interactions actually require it?
  • Loading: Must it run early, or can it be deferred, lazy-loaded, or triggered on interaction?
  • Impact: What requests, transfer size, main-thread work, and layout changes does it create?
  • Risk: What data does it access or send, what happens if the vendor fails, and how is it constrained?
  • Lifecycle: When will it be reviewed, updated, or removed?

Start with removal and tighter scope, then improve loading. Retest the real journey after every material change. A smaller, well-owned set of third-party services is easier to keep fast, secure, and understandable than a growing collection of unreviewed tags.

Ready to Get More Out of ScanMySEO?

Whether you're just getting started or already have scans to review, take the next step towards boosting your search presence.

Register for Free
Hansel McKoy

Hey there, I'm Hansel, the founder of ScanMySEO. I've spent over ten years helping global brands boost their digital presence through technical SEO and growth marketing. With ScanMySEO, I've made it easy for anyone to perform powerful, AI-driven SEO audits and get actionable insights quickly. I'm passionate about making SEO accessible and effective for everyone. Thanks for checking out this article!

Hansel McKoy

Founder, ScanMySEO


Get More Out of ScanMySEO