Cloudflare has launched a new feature called Speed Brain that customers can enable to help their websites load faster.
Speed Brain prefetches the most likely content a user may navigate to next by using Cloudflare’s Speculation Rules API.
“The main goal of Speed Brain is to download a web page to the browser cache before a user navigates to it, allowing pages to load almost instantly when the actual navigation takes place,” Cloudflare wrote in a blog post.
For example, it can infer from the global request logs of a clothing ecommerce site that the typical visitor viewing the “Mens > Clothes” page would next navigate to “Shirts.” Thus, Cloudflare starts delivering static content, like images, before the visitor even clicks on the button. Then, when the user actually clicks the link to navigate to “Shirts,” the page can load instantly.
It also has guardrails in place to prevent state prefetches (IE information changes over time and prefetches may include outdated information) and incorrect prefetching, which means a page was prefetched but never actually visited, resulting in wasted resources.
This is achieved via Document Rules, which allows prefetching to be dynamically applied across the webpage, and Eagerness, which controls how aggressively the browser prefetches content and has been set to conservative for the initial release.
“While we lose out on the potential performance improvements that the more aggressive eagerness settings offer, we chose this cautious approach to prioritize safety for our users. Looking ahead, we plan to explore more dynamic eagerness settings for sites that could benefit from a more liberal setting, and we’ll also expand our rules to include prerendering,” Cloudflare wrote.
Speed Brain is now available for all plan types for no additional cost. It has also been enabled by default already for free domains, and has to be turned on manually for Pro, Business, and Enterprise domains. It can be toggled on and off from the Cloudflare dashboard or API.
According to Cloudflare, early observations from the free domains who have this enabled show an average of 45% reduction in Largest Contentful Paint (LCP), which is “the time it takes for the largest visible element (like an image, video, or text block) to load and render in the browser.”