The Speculation Rules API is a JSON-defined API developed by Google to enhance the performance of web page loading through speculative loading strategies. One more description by Mozilla MDN.
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.
Prerender with the Speculation Rules API
Can I use Speculation Rules?
cd <magento_root>
composer require swissup/module-speculation-rules
bin/magento module:enable Swissup_SpeculationRules Swissup_Core
bin/magento setup:upgrade
cd <magento_root>
composer require swissup/module-speculation-rules:dev-master --prefer-source
bin/magento module:enable Swissup_SpeculationRules Swissup_Core
bin/magento setup:upgrade