diff --git a/.changeset/cdn-preconnect-bare-origin.md b/.changeset/cdn-preconnect-bare-origin.md new file mode 100644 index 000000000..f6b0fd9b4 --- /dev/null +++ b/.changeset/cdn-preconnect-bare-origin.md @@ -0,0 +1,5 @@ +--- +'@shopify/theme-check-common': patch +--- + +Report `CdnPreconnect` for `href="https://cdn.shopify.com"` and `href="//cdn.shopify.com"` without a trailing path, and stop reporting hosts that only contain `cdn.shopify.com` in their path. diff --git a/packages/theme-check-common/src/checks/cdn-preconnect/index.ts b/packages/theme-check-common/src/checks/cdn-preconnect/index.ts index 3165fc9f1..a336c429e 100644 --- a/packages/theme-check-common/src/checks/cdn-preconnect/index.ts +++ b/packages/theme-check-common/src/checks/cdn-preconnect/index.ts @@ -29,7 +29,10 @@ export const CdnPreconnect: LiquidCheckDefinition = { const isShopifyCdn = node.attributes .filter(isValuedHtmlAttribute) - .some((attr) => isAttr(attr, 'href') && valueIncludes(attr, '.+cdn.shopify.com.+')); + .some( + (attr) => + isAttr(attr, 'href') && valueIncludes(attr, '(https?:)?//cdn\\.shopify\\.com(/\\S*)?'), + ); if (!isShopifyCdn) return; diff --git a/specs/checks/cdn-preconnect.yml b/specs/checks/cdn-preconnect.yml index a06810b8f..7297876d8 100644 --- a/specs/checks/cdn-preconnect.yml +++ b/specs/checks/cdn-preconnect.yml @@ -19,6 +19,25 @@ cases: message: Preconnecting to cdn.shopify.com is unnecessary and can lead to worse performance start: [0, 0] highlight: '' + - name: should report preconnect to cdn.shopify.com without a trailing slash + files: + file.liquid: | + + + offenses: + - file: file.liquid + message: Preconnecting to cdn.shopify.com is unnecessary and can lead to worse performance + start: [0, 0] + highlight: '' + - file: file.liquid + message: Preconnecting to cdn.shopify.com is unnecessary and can lead to worse performance + start: [1, 0] + highlight: '' + - name: should not report preconnect to other hosts + files: + file.liquid: | + + - name: should not report other link types files: file.liquid: |