Speculative loading with Speculation Rules API for website

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.
Development and maintenance of all types of websites:
Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Our competencies:
Development stages
Latest works
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1041
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    822
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    847
  • image_website-sbh_0.png
    Website development for SBH Partners
    999
  • image_website-_0.png
    Website development for Red Pear
    451

Implementing Speculative Loading (Speculation Rules API) for Your Website

Speculation Rules API is a browser mechanism for prefetch and prerender pages before the user clicks a link. It enables instant navigation on supported browsers.

Difference from Classic Prefetch

Classic <link rel="prefetch"> loads the HTML document into the cache. Prerender via Speculation Rules goes further — the browser actually renders the page in a hidden tab, including JS execution, subresource loading, and DOM tree construction. When the user navigates, they see an already-prepared page.

Support: Chrome 109+, Edge 109+. Firefox and Safari — prefetch only, no prerender.

Basic Configuration

<script type="speculationrules">
{
  "prerender": [
    {
      "where": { "href_matches": "/product/*" },
      "eagerness": "moderate"
    }
  ],
  "prefetch": [
    {
      "where": { "href_matches": "/*" },
      "eagerness": "conservative"
    }
  ]
}
</script>

Eagerness Levels

Value Trigger Usage
immediate Upon parsing High-priority pages
eager Minimal interaction Main CTAs
moderate Hover 200ms Navigation
conservative Mousedown/touchstart All internal links

Document Rules vs List Rules

List Rules — explicit URL list:

{
  "prerender": [
    { "urls": ["/checkout", "/cart"] }
  ]
}

Document Rules — rules based on href patterns:

{
  "prefetch": [
    {
      "where": {
        "and": [
          { "href_matches": "/*" },
          { "not": { "href_matches": "/admin/*" } },
          { "not": { "href_matches": "*.pdf" } }
        ]
      }
    }
  ]
}

Dynamic Management via JS

// Programmatically add speculative loading rules
const script = document.createElement('script')
script.type = 'speculationrules'
script.text = JSON.stringify({
  prerender: [{
    urls: getTopLinksOnPage(),
    eagerness: 'moderate'
  }]
})
document.head.appendChild(script)

Limitations and Considerations

  • Server analytics — prerender initiates a real HTTP request. GA4 and Plausible handle this correctly via Activation API (page becomes active only on actual navigation), but server-side counters may inflate
  • Authenticated requests — prerender doesn't work for pages with Cache-Control: no-store
  • Mutating side-effects — pages that charge money or send emails on load should not be prerendered
  • Limit — browser limits concurrent prerender (typically 2 pages)

Verification

Chrome DevTools → Application → Speculation Rules shows status for each rule. document.prerendering — true if the page is currently being speculatively rendered.

document.addEventListener('prerenderingchange', () => {
  if (!document.prerendering) {
    // page activated — can initialize analytics
    initAnalytics()
  }
})

Timeline

Basic setup for a static website — 1 day. Integration with dynamic rules and analytics consideration — 2–3 days.