Eleventy plugin to add speculation rules to your build process
npm install eleventy-plugin-speculation-rulesThis plugin adds support for the Speculation Rules API, which allows defining rules by which certain URLs are dynamically prefetched or prerendered based on user interaction.
Demo: https://eleventy-plugin-speculation-rules.netlify.app/
- Eleventy 2.0 or higher (CJS) / Eleventy 3.0 or higher (ESM)
Install the plugin from npm:
```
npm install eleventy-plugin-speculation-rules --save-dev
- mode - The speculation mode. Default: prerender, options: prefetch, prerendereagerness
- - The eagerness level for speculation. Default: moderate, options: conservative, moderate, eagernoPrerenderSelector
- - CSS selector for links that should not be prerendered. Default: .no-prerenderinclude
- - Array of URL patterns to include. Default: []exclude
- - Array of URL patterns to exclude. Default: []
By default, the plugin excludes .zip and .pdf files, as well as links with rel="nofollow".
Add it to your Eleventy Config file:
ESM (Eleventy 3.x):
`js
import eleventyPluginSpeculationRules from 'eleventy-plugin-speculation-rules';
export default function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginSpeculationRules);
};
`
CommonJS (Eleventy 2.x):
`js
const eleventyPluginSpeculationRules = require('eleventy-plugin-speculation-rules');
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginSpeculationRules);
};
`
`js
import eleventyPluginSpeculationRules from 'eleventy-plugin-speculation-rules';
export default function (eleventyConfig) {
eleventyConfig.addPlugin(eleventyPluginSpeculationRules, {
mode: 'prerender',
eagerness: 'moderate',
noPrerenderSelector: '.no-prerender',
include: [],
exclude: ['/admin/*']
});
};
`
The plugin injects a