full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -23,6 +23,14 @@ export interface PrefetchOptions {
* Should prefetch even on data saver mode or slow connection. (default `false`)
*/
ignoreSlowConnection?: boolean;
/**
* A string providing a hint to the browser as to how eagerly it should prefetch/prerender link targets in order to balance performance advantages against resource overheads. (default `immediate`)
* Only works if `clientPrerender` is enabled and browser supports Speculation Rules API.
* The browser takes this hint into consideration along with its own heuristics, so it may select a link that the author has hinted as less eager than another, if the less eager candidate is considered a better choice.
*
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/speculationrules#eagerness
*/
eagerness?: 'immediate' | 'eager' | 'moderate' | 'conservative';
}
/**
* Prefetch a URL so it's cached when the user navigates to it.

View File

@@ -125,7 +125,7 @@ function prefetch(url, opts) {
prefetchedUrls.add(url);
if (clientPrerender && HTMLScriptElement.supports?.("speculationrules")) {
debug?.(`[astro] Prefetching ${url} with <script type="speculationrules">`);
appendSpeculationRules(url);
appendSpeculationRules(url, opts?.eagerness ?? "immediate");
} else if (document.createElement("link").relList?.supports?.("prefetch") && opts?.with !== "fetch") {
debug?.(`[astro] Prefetching ${url} with <link rel="prefetch">`);
const link = document.createElement("link");
@@ -182,14 +182,15 @@ function onPageLoad(cb) {
cb();
});
}
function appendSpeculationRules(url) {
function appendSpeculationRules(url, eagerness) {
const script = document.createElement("script");
script.type = "speculationrules";
script.textContent = JSON.stringify({
prerender: [
{
source: "list",
urls: [url]
urls: [url],
eagerness
}
],
// Currently, adding `prefetch` is required to fallback if `prerender` fails.
@@ -198,7 +199,8 @@ function appendSpeculationRules(url) {
prefetch: [
{
source: "list",
urls: [url]
urls: [url],
eagerness
}
]
});

View File

@@ -1,5 +1,5 @@
import type * as vite from 'vite';
import type { AstroSettings } from '../@types/astro.js';
import type { AstroSettings } from '../types/astro.js';
export default function astroPrefetch({ settings }: {
settings: AstroSettings;
}): vite.Plugin;

View File

@@ -25,7 +25,7 @@ function astroPrefetch({ settings }) {
load(id) {
if (id === resolvedVirtualModuleId) {
if (!prefetch) throwPrefetchNotEnabledError();
return `export { prefetch } from "astro/virtual-modules/prefetch.js";`;
return { code: `export { prefetch } from "astro/virtual-modules/prefetch.js";` };
}
},
transform(code, id) {