From 67f2ff697ebf63ab8f9c9d52acc13d705c6215c2 Mon Sep 17 00:00:00 2001 From: GauthierWebDev Date: Thu, 17 Apr 2025 20:04:47 +0200 Subject: [PATCH] feat: Add prefetching for links to improve performance --- app/components/common/Link.tsx | 4 ++++ og_maker.afphoto~lock~ | Bin 105 -> 105 bytes 2 files changed, 4 insertions(+) diff --git a/app/components/common/Link.tsx b/app/components/common/Link.tsx index 1dc34f5..a9c00ea 100644 --- a/app/components/common/Link.tsx +++ b/app/components/common/Link.tsx @@ -1,4 +1,5 @@ import { usePageContext } from "vike-react/usePageContext"; +import { prefetch } from "vike/client/router"; import clsx from "clsx"; export function Link(props: React.AnchorHTMLAttributes & { href: string }) { @@ -7,6 +8,8 @@ export function Link(props: React.AnchorHTMLAttributes & { hr const isSameDomain = !(props.href.startsWith("http") || props.href.startsWith("mailto")); const isDownload = props.href.endsWith(".pdf") || props.href.endsWith(".zip"); + const handleMouseEnter = () => prefetch(props.href); + return ( & { hr className={clsx(isActive && "is-active", props.className)} {...(isDownload ? { download: true } : {})} {...(!isSameDomain || isDownload ? { target: "_blank", rel: "noopener noreferrer" } : {})} + {...(isSameDomain ? { onMouseEnter: handleMouseEnter } : {})} > {props.children} diff --git a/og_maker.afphoto~lock~ b/og_maker.afphoto~lock~ index 3bfcaed0b3d4269538cbbafe40941427bc01bd5d..98c3643c209a6e4948afd9cffa1bc696b417d6f9 100644 GIT binary patch delta 20 Zcmd1I(88(EvN+1xo+`