duckweb_speculate
scalar · LOAD duckweb
duckweb_speculate(VARCHAR, VARCHAR, VARCHAR) -> VARCHARA speculation rules block, telling the browser which navigations to prepare for.
duckweb_head(200, 'text/html',
duckweb_speculate('prerender', '/species/*', 'moderate'))Emits a <script type="speculationrules"> block covering every link whose href matches pattern, so a click resolves against work the browser has already done.
actionisprefetch(fetch the response) orprerender(fetch it and render it in a hidden tab). Anything else yields an empty string rather than a rule the browser would reject.patternis a URL pattern, so an exact path is simply a pattern with no wildcard — there is no separate list-of-urls form to choose between.eagernessisimmediate,eager,moderateorconservative; empty leaves it out and takes the browser’s default for that action.
This pairs with the client tiers: the worker answers a navigation locally, and a prerender means it has already answered it before the click.
The pattern is escaped twice over — as a JSON string, and against the HTML parser’s scan for </script, which does not care that it is inside one.