Skip to main content
TagManifest /Docs Dashboard

Duplicate external script loaded

The same external script is loaded by multiple tags, creating redundant network requests and potential race conditions.

On this page 6

Summary

  • rule_id — duplicate-external-script
  • purpose — Detect the same external script URL loaded by two or more Custom HTML tags
  • effect — Redundant network requests and race conditions when two tags initialize the same library
  • layer — container
  • reversibility — non-destructive

What fires this

The rule reads codeAnalysis.externalScriptUrls from each active Custom HTML tag. Paused tags are excluded. URLs are normalized by stripping the protocol (https:// or http://) and any trailing slash. When the same normalized URL appears in two or more tags, the rule emits one finding per duplicate URL. A container with three distinct duplicated URLs produces three separate findings.

Why it matters

Each tag that loads the same script URL issues an independent network request. For uncached resources, those requests block or delay dependent code. Race conditions are the sharper risk: when two tags load the same library simultaneously, the second initialization may corrupt shared state, reset configuration, or cause the library to report inflated counts. This pattern appears most often with jQuery, vendor analytics SDKs, and consent management libraries loaded once by a base template and again by a vendor snippet.

Before / after

Two separate Custom HTML tags both load the same script URL.

Tag A — "Google Maps Loader":

<script src="https://maps.googleapis.com/maps/api/js?key=ABC"></script>

Tag B — "Maps Widget Init":

<script src="https://maps.googleapis.com/maps/api/js?key=ABC"></script>
<script>initMap()</script>

One dedicated loader tag loads the script once. The init tag declares it as a setup dependency via Tag Sequencing and removes the duplicate <script> call.

Tag A — "Google Maps Loader" (unchanged):

<script src="https://maps.googleapis.com/maps/api/js?key=ABC"></script>

Tag B — "Maps Widget Init" (deduplicated):

<script>initMap()</script>

Tag B uses Tag Sequencing → Setup Tag: "Google Maps Loader".

Remediation

  1. Open the finding detail and note all tags loading the duplicated URL.
  2. Designate one of those tags as the sole loader. Remove any other logic from it — load only the script.
  3. In all remaining tags, delete the duplicate <script src="…"> call.
  4. Use GTM (Google Tag Manager) Tag Sequencing to make each dependent tag wait for the loader tag to fire successfully.
  5. Add a guard in the loader tag to prevent double-loading if the tag fires more than once: if (!window.libraryNamespace) { /* load script */ }.
  6. Verify in Preview mode that the script loads exactly once and all dependent tags function correctly.

Metadata

Severity
medium
Tier
optimization
Category
performance
Layer
container
Version
1
Effort
2hr (about 2 hours)
Reversibility
non-destructive

See also

Examples

Evaluate
curl https://developer.tagmanifest.com/v1/evaluate-rule \
  -H "Authorization: Bearer $TM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rule_id":"duplicate-external-script","url":"https://example.com"}'