Speculation Rules Auditor avatar

Speculation Rules Auditor

Pricing

Pay per usage

Go to Apify Store
Speculation Rules Auditor

Speculation Rules Auditor

Audit a public page for Speculation Rules API usage: inline <script type="speculationrules"> blocks and the Speculation-Rules HTTP header. Returns per-rule analysis, eagerness, issues, score, grade, and Core Web Vitals recommendations.

Pricing

Pay per usage

Rating

0.0

(0)

Developer

Sanskar Jaiswal

Sanskar Jaiswal

Maintained by Community

Actor stats

0

Bookmarked

2

Total users

1

Monthly active users

22 days ago

Last modified

Share

Audit a public web page for Speculation Rules API usage in one API call. Detects inline <script type="speculationrules"> blocks and the Speculation-Rules HTTP response header, parses each prefetch/prerender rule, validates JSON syntax and rule shapes, flags broad matchers without exclusions, and returns a readiness score, letter grade, and Core Web Vitals recommendations. Built for performance engineers, SEO teams, and site migration QA.

Use cases

  • Performance engineers - verify prefetch and prerender rules are present, valid, and correctly scoped before launches
  • SEO teams - confirm Speculation Rules survive CMS template changes and migrations
  • Site migration QA - catch missing or malformed speculation rules when moving between frameworks, CDNs, or edge providers
  • Frontend platform teams - monitor for broad href_matches: /* rules without exclusions that risk wasted prerenders and side-effecting GETs
  • Agency consultants - batch-audit client pages and return structured recommendations

Input

FieldTypeRequiredDefaultDescription
startUrlstringyes-Public page URL to audit
timeoutSecondsintegerno10Per-request timeout (3-30 seconds)
maxHtmlBytesintegerno1048576Maximum HTML body size to download and parse (16 KB - 2 MB)

Example input

{
"startUrl": "https://example.com",
"timeoutSeconds": 10,
"maxHtmlBytes": 1048576
}

Output

A single dataset item with the full audit:

FieldTypeDescription
inputUrlstringThe URL provided as input
finalUrlstringFinal URL after redirects
httpsbooleanWhether the final response was served over HTTPS
inlineRuleCountintegerNumber of inline <script type="speculationrules"> blocks found
speculationRulesHeaderstring | nullValue of the Speculation-Rules HTTP response header, or null when absent
headerRuleUrlsarrayURLs referenced by the Speculation-Rules header (resolved against the page), empty when header absent
byActionobjectCount of rules grouped by action (prefetch, prerender)
eagernessLevelsarrayDistinct eagerness values used across rules (immediate, eager, moderate, conservative)
totalRulesintegerTotal number of prefetch and prerender rule entries parsed
ruleBlocksarrayPer-block analysis (see below)
issuesarrayAggregated issue descriptions across all rule blocks
scoreintegerSpeculation rules readiness score (0-100)
gradestringLetter grade (A+, A, B, C, D, E, F)
checkedAtstringISO 8601 timestamp
recommendationsarrayActionable recommendations for improving Speculation Rules API readiness

ruleBlocks array

Each entry is one inline block or one header reference:

FieldTypeDescription
sourcestringinline for <script type="speculationrules"> blocks, header for Speculation-Rules header references
parseErrorstring | nullJSON parse error message, or null when the block parsed successfully
actionsFoundarrayActions present in the block (prefetch, prerender)
ruleCountintegerNumber of rule entries in the block
rulesarrayPer-rule analysis (see below) for inline blocks
issuesarrayIssue descriptions for this block
urlsarrayFor header blocks, the resolved rule-file URLs
urlCountintegerFor header blocks, the number of resolved URLs

rules array (within inline ruleBlocks)

Each entry describes one prefetch or prerender rule:

FieldTypeDescription
actionstringprefetch or prerender
hasUrlsbooleanWhether the rule has a urls array
hasWherebooleanWhether the rule has a where predicate
urlsCountintegerNumber of distinct non-empty URLs in urls
wherePredicatestring | nullRecognized predicate in where (href_matches, selector_matches, and, not), or null
eagernessstring | nullEagerness value (immediate, eager, moderate, conservative)
defaultEagernessAppliedbooleanTrue when eagerness was defaulted because the rule omitted it
issuesarrayIssue descriptions for this rule

Rules checked

The Speculation Rules API uses JSON objects inside <script type="speculationrules"> blocks or files referenced by the Speculation-Rules HTTP response header:

{
"prefetch": [{ "urls": ["/next"], "eagerness": "eager" }],
"prerender": [{ "where": { "href_matches": "/*", "not": { "href_matches": "/logout" } }, "eagerness": "moderate" }]
}

This actor parses each block and flags:

  • Malformed JSON (browsers silently ignore unparseable blocks)
  • Rules with neither urls nor where
  • Rules with both urls and where (spec: urls should be exclusive)
  • urls arrays that are not arrays, empty, contain non-strings, empty strings, or duplicates
  • where objects with no recognized predicate
  • Broad href_matches: /* or * matchers without a not exclusion for state-changing paths (e.g., /logout)
  • Prerender with immediate or eager eagerness and more than 3 URLs (exceeds Chrome's recommended 1-2 immediate prerenders)
  • Prerender with aggressive eagerness on broad matchers without exclusions
  • Invalid eagerness values

Grading scale

Score rangeGrade
95-100A+
85-94A
75-84B
65-74C
50-64D
30-49E
0-29F

Scoring rewards genuine adoption (inline blocks, header references, prefetch, prerender, and a graduated prefetch-plus-prerender strategy), then subtracts penalties for each issue. An empty page (no rules and no header) scores 0 because Speculation Rules are opt-in, not a defect.

Example output

{
"inputUrl": "https://example.com",
"finalUrl": "https://example.com/",
"https": true,
"inlineRuleCount": 1,
"speculationRulesHeader": null,
"headerRuleUrls": [],
"byAction": { "prefetch": 1, "prerender": 1 },
"eagernessLevels": ["eager", "moderate"],
"totalRules": 2,
"ruleBlocks": [
{
"source": "inline",
"parseError": null,
"actionsFound": ["prefetch", "prerender"],
"ruleCount": 2,
"rules": [
{ "action": "prefetch", "hasUrls": true, "hasWhere": false, "urlsCount": 2, "wherePredicate": null, "eagerness": "eager", "defaultEagernessApplied": false, "issues": [] },
{ "action": "prerender", "hasUrls": false, "hasWhere": true, "urlsCount": 0, "wherePredicate": "and", "eagerness": "moderate", "defaultEagernessApplied": false, "issues": [] }
],
"issues": []
}
],
"issues": [],
"score": 100,
"grade": "A+",
"checkedAt": "2026-08-14T12:00:00.000Z",
"recommendations": [
"Combine an eager prefetch of common next pages with a moderate prerender for the rest, so prefetches warm before hover-triggered prerenders.",
"Speculation Rules look well-configured. Schedule this audit periodically to catch CMS template regressions and rule-rot."
]
}

Security

  • Only public HTTP/HTTPS URLs are accepted
  • SSRF protection: localhost, private IPv4/IPv6, and DNS-resolving-to-private IPs are blocked
  • URLs with embedded credentials are rejected
  • Redirects are manually revalidated before following (max 3)
  • HTML body is capped at maxHtmlBytes to prevent oversized responses
  • The actor does not fetch the URLs referenced by the Speculation-Rules header; it only reports them
  • No browser automation, no proxies, no cookies stored

Pricing

Pay per event:

EventPrice
Actor start$0.005
Page audited$0.01

A single-page audit costs approximately $0.015.

FAQ

What is the Speculation Rules API? The Speculation Rules API lets pages hint to the browser which future navigations to prefetch or prerender. Rules are JSON objects inside inline <script type="speculationrules"> elements or external files referenced by the Speculation-Rules HTTP response header. Each rule targets a urls list or a where predicate (with href_matches or selector_matches) and an eagerness level (immediate, eager, moderate, conservative).

How is this different from a resource hints auditor? A resource hints auditor inspects <link rel="preload">, preconnect, prefetch, dns-prefetch, and modulepreload tags. This actor focuses exclusively on the newer Speculation Rules API, which targets document navigations (not individual resource fetches) and uses a JSON rule structure with eagerness levels and where predicates. The two are complementary, not overlapping.

Does the actor fetch the external rule file referenced by the Speculation-Rules header? No. The actor reports the header value and resolves the referenced URLs against the page, but it does not download the external rule file. Fetching user-controlled secondary URLs would add another SSRF surface for marginal value; the inline block analysis already covers the common deployment.

Can I audit multiple pages in one run? This actor audits one page per run. For bulk audits, schedule multiple runs.

Does the actor follow redirects? Yes, up to 3 redirects. Each redirect target is revalidated for SSRF safety before it is followed.