recipes: preload hero images with high priority
All checks were successful
CI / update (push) Successful in 3m1s

Add fetchpriority="high" and <link rel="preload"> hints to hero images
on both the recipe listing and detail pages. Also prefetch the full-size
hero image on card hover via new Image() to warm the cache before navigation.
This commit is contained in:
2026-02-26 19:49:10 +01:00
parent 2f4c3ac1ae
commit aa07ebc3b0
4 changed files with 11 additions and 2 deletions

View File

@@ -38,6 +38,10 @@ const img_alt = $derived(
);
const img_color = $derived(recipe.images?.[0]?.color || '');
function preloadHeroImage() {
new Image().src = `https://bocken.org/static/rezepte/full/${img_name}`;
}
</script>
<style>
.card-main-link {
@@ -226,7 +230,7 @@ const img_color = $derived(recipe.images?.[0]?.color || '');
</style>
<div class="card" class:search_me={search} class:margin_right={do_margin_right} data-tags="[{recipe.tags}]">
<a href="{routePrefix}/{recipe.short_name}" class="card-main-link" aria-label="View recipe: {recipe.name}">
<a href="{routePrefix}/{recipe.short_name}" class="card-main-link" aria-label="View recipe: {recipe.name}" onpointerenter={preloadHeroImage}>
<span class="visually-hidden">View recipe: {recipe.name}</span>
</a>
<div class="card-image" style:background-color={img_color}>

View File

@@ -145,7 +145,7 @@ dialog button{
<!-- svelte-ignore a11y_no_static_element_interactions -->
<div class:zoom-in={!isredirected} onclick={show_dialog_img}>
<div class="image-wrap" style:background-color={color}>
<img class="image" {src} {alt} style:view-transition-name={transitionName || null}/>
<img class="image" {src} {alt} style:view-transition-name={transitionName || null} fetchpriority="high"/>
</div>
<noscript>
<div class="image-wrap" style:background-color={color}>

View File

@@ -338,6 +338,9 @@
<svelte:head>
<title>{labels.metaTitle}</title>
<meta name="description" content="{labels.metaDescription}" />
{#if heroRecipe}
<link rel="preload" as="image" href="https://bocken.org/static/rezepte/full/{heroImg}" fetchpriority="high" />
{/if}
<meta property="og:image" content="https://bocken.org/static/rezepte/thumb/ragu_aus_rindsrippen.webp" />
<meta property="og:image:secure_url" content="https://bocken.org/static/rezepte/thumb/ragu_aus_rindsrippen.webp" />
<meta property="og:image:type" content="image/webp" />
@@ -352,6 +355,7 @@
src="https://bocken.org/static/rezepte/full/{heroImg}"
alt=""
loading="eager"
fetchpriority="high"
data-recipe={heroRecipe.short_name}
/>
<div class="hero-overlay"></div>

View File

@@ -300,6 +300,7 @@ h2{
<svelte:head>
<title>{data.strippedName} - {labels.title}</title>
<meta name="description" content="{data.strippedDescription}" />
<link rel="preload" as="image" href={hero_img_src} fetchpriority="high" />
<meta property="og:image" content="https://bocken.org/static/rezepte/thumb/{img_filename}" />
<meta property="og:image:secure_url" content="https://bocken.org/static/rezepte/thumb/{img_filename}" />
<meta property="og:image:type" content="image/webp" />