Skip to main content
InterviewHubPRO
Section Overview
Q38

Question 38 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

76%
Web Vitals & Performance (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Speculative Rules API: Instant Page Navigations.

senior LevelCode ExampleRoutingSystem DesignHTTP & REST APIs

In Simple Words: The Speculation Rules API allows pages to programmatically instruct the browser to pre-render full destination pages in a hidden background process before the user clicks a link:

  • prerender: Fetches the HTML and executes JavaScript in the background. Clicking the link results in an instantaneous ($0\text{ms}$) navigation!
  • prefetch: Fetches the HTML response document into browser cache.
html
<script type="speculationrules">
{
  "prerender": [
    {
      "where": {
        "and": [
          { "href_matches": "/sections/*" },
          { "not": { "href_matches": "/logout" } }
        ]
      },
      "eagerness": "moderate"
    }
  ]
}
</script>