2024 is shaping up to be the time when instant loading becomes the new standard in web performance, and online business owners are all ears.
The transition from fast to instant has been in the works for a while, though.
As early as 2009, the quest for faster and more efficient page loading led the Chromium team to create the first resource hints, to which link rel=”prerender” was later added.
It was expected to have a significant impact on performance since it involved loading subsequent pages in the background before a user navigates to them, ensuring faster rendering when the transition occurred.
However, this version of prerendering didn’t prove efficient enough and was deprecated in 2017.
Fast-forward to today, Google launched promising developments to its Speculation Rules API, allowing for a more sophisticated approach to full prerendering and unlocking truly seamless web browsing.
The Speculation Rules API is a JSON-defined API developed by Google to enhance the performance of web page loading through speculative loading strategies.
Speculative loading involves predicting and preloading resources for subsequent page navigations, leading to faster rendering times and improved user experiences. Google introduced this API to provide developers with a more flexible and expressive way to specify which documents should be prefetched or prerendered.
Key details about the Speculation Rules API:
You could also check if the browsers support the API with the following code:
The Speculation Rules API empowers near-instant page loads for seamless browsing experiences.
Improved page load times, enhanced user satisfaction and potential SEO advantages are compelling reasons for developers to embrace this technology.
By reducing the latency between page navigations, users perceive the website as more fluid and responsive. This becomes clearly visible in your site’s Core Web Vitals, where Largest Contentful Paint (LCP), Cumulative Layout Shift (CLS), and Interaction to Next Paint (INP) drastically decrease.
With instant browsing, experiences come lower bounce rates and increased user retention – vital metrics for the success of your online platform. Thus underscoring the strategic value of integrating the Speculation Rules API.
Google's Speculation Rules API is designed to target document URLs rather than specific resource files. The Speculation Rules API introduces a more expressive and configurable syntax for specifying which documents should be prefetched or prerendered.
With a structure defined in JSON format within a script type="speculationrules", developers can articulate rules for both prerendering and prefetching. This enhanced flexibility allows for fine-tuning speculative loading.
Recently, Google announced a new enhancement to the Speculation Rules API in Chrome 121, which now provides the option for automatic link finding.
This is done by:
However, if you’re new to Speculation Rules API, we recommend you first test out the different setups below.
The Speculation Rules API allows developers to follow a structured approach to optimizing the prerendering and prefetching processes.
It starts with first creating a script type="speculationrules" element and defining speculation rules in a JSON structure within it.
Speculation rules can be added in either the head or the body of the mainframe.
Important: Speculation rules in subframes are not acted upon, and speculation rules in prerendered pages are only acted upon once a user navigates to the page itself.
Speculation rules can be included either statically or dynamically.
Important: When opting for the dynamic setup, always refer back to the support documentation for future developments and use cases that might become available in the future.
To inform the browser which URLs to prerender, you can insert JSON instructions onto your pages:
{ |
"prerender": [ |
{ |
"source": "list", |
"urls": ["next.html", "next2.html"] |
} |
] |
} |
Similarly, insert the following JSON instructions for prefetching: It’s possible to add multiple speculation rules to a page, in which case you would instruct the browser on any of the following levels:
Specifying Routes For Prerender/PrefetchFine-tuning speculative loading involves specifying routes for prerendering and prefetching. By categorizing pages based on their significance or likelihood of user navigation, developers can optimize the speculative loading strategy. However, there are some routes that are considered unsafe, such as:
Similar to excluding such pages from caching, the reason for avoiding prefetching and prerendering them is related to dynamic variables. These are content-sensitive pages where values update based on user actions, and by preloading them in the background, the risk of showing an outdated state of the page is very high. Accuracy and Trade-OffsAs Barry Pollard mentioned in our webinar on “Loading Pages Instantly”: “[Using prefetching and prerendering] It’s about the balance trying to figure out what you can do to reduce waste efficiency (% of correct predictions) and increase prediction accuracy (# of predictions used).”
While prefetching is the safest approach you can duplicate across many of your web pages, it also offers the lowest reward since it only involves downloading specific resources. Full-page prerenders, on the other hand, offer higher rewards, but they should be used sparingly since they can:
To set up prerendering properly, you should consider your users’ behavior and analyze common navigations across your website. Using heatmaps and Google Analytics flow charts, you can identify essential routes and start your predictive loading experiments. To check if a page is prerendered, use a non-zero activationStart entry of PerformanceNavigationTiming. This can then be logged using a Custom Dimension: This way, you’ll be able to gauge the ratio between prerender and other types of navigations. Additionally, it’s important to measure the number of prerendered pages that are not subsequently visited to optimize speculation rules and achieve higher hit rates and lower resource waste. You can either do this by firing an analytics event when speculation rules are inserted to indicate that prerender was requested. Then compare the number of these events to the actual prerender page views. Or you can… Consider Automated Page Prerendering With Navigation AI By NitroPackNavigation AI is NitroPack's AI-powered web browsing optimizer that actively predicts and analyzes user behavior to prerender full pages during the customer journey. Navigation AI empowers site owners to offer instant browsing experiences on desktop and mobile without writing a single line of code, boosting customer engagement and conversion rates. Note: Navigation AI is a separate product, but it is 100% compatible with NitroPack and further extends the benefits for site owners. Join the waitlist for Navigation AI and unlock instant user experiences on your site →Navigation AI by NitroPack builds upon the Speculation Rules API and offers an automated solution to striking a high hit ratio and resource efficiency in prerendering scenarios. By applying AI-enhanced initial predictions on page load based on data and analyzing user behavior, Navigation AI can adjust the predictions and accurately instruct the Speculation Rules API to prerender pages that will actually be visited. The result is instantaneous page load thanks to having this page already painted in the background. On mobile devices, Navigation AI relies on identifying where the user is on the page, and given the small viewport, it can easily predict where they’ll tap. Based on 1,200 websites, Navigation AI is already showing spectacular results.
Get access to Navigation AI by joining our waitlist →Speculation Rules API and WordPressIn our “Instant Page Loading” webinar, Google’s Developer Relations Engineer Adam Silverstein revealed that the WordPress Core Performance team is working on more stable implementations of the new Speculation Rules API.
WP-admin routes are excluded by default, but it is up to WP developers to make out the routes they’d like to prioritize. The WordPress Core Performance team is also working on more sophisticated implementations within plugins in the ecosystem. This aims to alleviate some of the heavy work developers have to do when figuring out which routes are top priority and which ones are a no-go. Recent Updates to the Speculation Rules APIIn early March this year, the Chromium team introduced several improvements to how Speculation Rules API works: Document Rules
Why is this helpful:
Eagerness Setting
Why is this helpful:
Chrome Limits
Why is this helpful:
Speculation-Rules HTTP Header
What Improvements Are Coming To Speculation RulesCurrently, speculation rules are limited to pages within the same tab, but efforts are underway to reduce these restrictions. Prerendering is, by default, confined to same-origin pages. However, a recent update in Chrome 119 now supports prerendering for same-site cross-origin pages, requiring opt-in through an HTTP header. Future versions may extend prerendering to cross-origin pages and allow it in new tabs. The Speculation Rules API is set to expand, introducing scores and syntax for document rules and providing more flexibility, such as prerendering links on mouse down. Ongoing experiments in Chrome are exploring additional features, and sites can participate in an origin trial to test and provide feedback on potential future additions. Lora has 7+ years of experience developing in-depth, specialized content for SaaS companies in the CEE region. She has sourced and collaborated with subject-matter experts on site speed optimization for WordPress, Core Web Vitals, and the future of web performance. "If you can't explain it to a 7-year-old, you've not researched it well enough" is Lora's guiding principle when publishing professional insight for complex technical topics. |