Skip to main content
TagManifest /Docs Dashboard

jQuery dependency in custom HTML

Active custom HTML tags use jQuery ($() or jQuery()). If jQuery is not available when these tags fire, they fail silently.

On this page 6

Summary

  • rule_id — jquery-dependency
  • purpose — Detect active Custom HTML tags that call $() or jQuery() without a guaranteed loader
  • effect — Tags fail silently at runtime if jQuery is absent when they fire
  • layer — container
  • reversibility — non-destructive

What fires this

The rule filters active Custom HTML tags where codeAnalysis.hasJquery is true. For each matching tag, it checks whether any tag in the container loads jQuery by scanning codeAnalysis.externalScriptUrls for URLs matching /jquery/i. If no loader is found, the issue message notes that the site itself must provide jQuery. If loaders exist, the message flags that load order is not guaranteed. Paused tags are excluded from both passes.

Why it matters

Tag containers fire asynchronously. jQuery may not be present in window.$ when a custom HTML tag executes, even if the page ultimately loads it. The call to $() or jQuery() throws a TypeError silently — no console error surfaces in production, and the tag's intended action (conversion tracking, form enrichment, data push) never runs. Rewriting to vanilla JS removes the runtime dependency entirely and reduces overall page weight if jQuery was loaded solely for tag use.

Before / after

// Custom HTML tag — fails if $ is undefined at fire time
var formId = $('form').attr('id')
dataLayer.push({ event: 'form_detected', form_id: formId })
// Vanilla JS — no jQuery dependency
var form = document.querySelector('form')
var formId = form ? form.getAttribute('id') : null
dataLayer.push({ event: 'form_detected', form_id: formId })

Remediation

  1. Open each flagged tag in the container editor.
  2. Identify every $() or jQuery() call and determine its DOM equivalent.
  3. Replace jQuery selector calls with document.querySelector or document.querySelectorAll.
  4. Replace jQuery utility calls (.attr, .val, .on, .each) with native equivalents.
  5. If removing jQuery from tags would leave no other jQuery consumers, remove the jQuery script loader tag as well.
  6. Publish and verify tags fire correctly in Tag Assistant or equivalent preview mode.

Metadata

Severity
high
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":"jquery-dependency","url":"https://example.com"}'