Skip to content

perf/dom-size: dom-max-children counts the children of <head> #483

Closed

Description

@deniskern

Scope note: this issue now covers part 1 only (dom-max-children counting <head>). Part 2 (security/sri on Shopify platform scripts) is tracked in #546.

Summary

Two rules raise findings on Shopify stores that the store owner cannot act on:

  1. perf/dom-size (dom-max-children) counts the children of <head>. A multi-language store with hreflang alternates trips the 60-children limit on <head> while no body element comes close.
  2. security/sri flags scripts whose content changes server-side by design, so a pinned SRI hash would break them. SRI_EXEMPT_HOSTNAMES already exempts this class for Stripe, PayPal, GTM, GA and Facebook, but not for Shopify platform scripts or other unversioned "latest" SDK URLs.

1. dom-max-children counts <head>

Repro page (70 hreflang links, tiny body), served with python3 -m http.server 8766:

<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Many hreflang alternates</title>
<link rel="alternate" hreflang="l0" href="http://127.0.0.1:8766/l0/">
<!-- … 69 more alternates … -->
</head><body><h1>Hello</h1><p>Small body.</p></body></html>
squirrel audit http://127.0.0.1:8766/ -m 1 --http --offline --disable-discovery-probes \
  --rule-include perf/dom-size -f json -o out.json -y

Actual: dom-max-children — "Element with 72 children found" (the <head>).
Real store: https://www.alpensattel.de/ (9 languages, 30 hreflang links) reports "Element with 142 children found"; the widest body element has 38 children.

Expected: findMaxChildren walks <body> only. The rule's rationale (layout/style recalculation cost of wide nodes) does not apply to <head> metadata, and hreflang alternates are the documented Google method for multi-language sites.

2. security/sri on self-updating scripts

squirrel audit https://www.alpensattel.de/ -m 8 --http --offline --disable-discovery-probes \
  --rule-include security/sri -f json -o out.json -y

Actual: "7 cross-origin resources without Subresource Integrity", including:

  • https://cdn.shopify.com/shopifycloud/shop-js/modules/v2/loader.init-shop-cart-sync.de.esm.js (injected by Shopify)
  • https://cdn.shopify.com/storefront/standard-actions.js (injected by Shopify)
  • https://cdn.shopify.com/extensions/<uuid>/<app>/assets/<name>-latest.js (theme app extension, path ends in -latest)
  • https://static.klaviyo.com/onsite/js/<id>/klaviyo.js
  • https://plausible.io/js/script.pageview-props.revenue.tagged-events.js

The store owner does not control the Shopify-injected tags at all, and the vendor SDKs are updated in place, which is the same reason the existing exemption list gives for Stripe/GTM.

Expected: exempt cdn.shopify.com/shopifycloud/ and cdn.shopify.com/storefront/ (platform-injected), and treat unversioned SDK URLs (-latest.js, vendor onsite loaders such as Klaviyo and Plausible) like the existing SRI_EXEMPT_HOSTNAMES, or at least downgrade them to info.

Version

squirrel 0.0.103.

Acceptance Criteria

  • A page with 70 <link> children in <head> (hreflang alternates, as in the original repro, or preload hints, as in the comment) and a small body produces no dom-max-children finding from perf/dom-size
  • The reported max-children count and element reflect <body> descendants only
  • A body element with more children than the threshold is still reported
  • Only dom-max-children changes in this issue. Total-node count and depth keep their current behaviour (tracked separately)
  • docs/rules/perf/dom-size.mdx states what is counted
  • Test: new packages/rules/tests/dom-size.test.ts, 70 hreflang links in <head> plus a small body: no finding
  • Test: same file, 70 preload links in <head>: no finding
  • Test: same file, a <ul> with 61 <li> in the body: reported with value 61
  • Test: same file, a document with no <body> element does not throw
  • The PR description states whether the squirrelscan agent skill needs a change (the skill links to the rule pages, which are the reference, so usually none); if it does, a follow-up is filed against squirrelscan/skills

Activity

  1. deniskern commented on Oct 6, 2026

    @deniskern
    Author

    Addendum for part 1: this is not Shopify-specific. Any page with many <head> children trips it, e.g. preload hints.

    Repro on 0.0.104: a page with 70 <link rel="preload" as="image" href="/img/N.webp"> in <head> and a small body:

    squirrel audit http://127.0.0.1:8797/ -m 30 --http --offline --disable-discovery-probes -C full \
      --rule-include perf/dom-size -f json -o out.json -y

    Actual: dom-max-children — "Element with 73 children found" on / (the <head>). Same fix: walk <body> only.

  2. added
    P2
    bug
    rules
    size: S
    size: XS
    and removed
    size: S
    on Oct 7, 2026
  3. changed the title [-]Shopify stores: dom-max-children counts <head>, security/sri flags self-updating platform scripts[/-] [+]perf/dom-size: dom-max-children counts the children of <head>[/+] on Oct 7, 2026
  4. nc9 commented on Oct 7, 2026

    @nc9
    Contributor

    Triage notes (maintainer review):

    • This issue combined two different rules, so it is split. This issue now covers part 1 only (perf/dom-size, dom-max-children counting <head>). Part 2 (security/sri and Shopify platform scripts) moves to security/sri: exempt Shopify platform scripts and add an exempt_hosts option #546 so each can be a separate PR. The repro, the addendum and the real-store numbers above stay valid for this part.
    • Confirmed on current main: the walker starts at the document element, so <head> is counted. Lighthouse measures from body, so this also improves parity.
    • Scope decision: only dom-max-children changes here. Total nodes and depth also include <head> today; changing them shifts counts on every site, so that is a separate follow-up (perf/dom-size: scope total node count and depth consistently with dom-max-children #548).
    • Priority P2, size XS. Acceptance criteria rewritten with the unit tests split out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2bugrulessize: XS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions