feat: Add prefetching for links to improve performance
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 53s
All checks were successful
Update Memento Dev on VPS / deploy (push) Successful in 53s
This commit is contained in:
parent
48a644b74a
commit
67f2ff697e
@ -1,4 +1,5 @@
|
|||||||
import { usePageContext } from "vike-react/usePageContext";
|
import { usePageContext } from "vike-react/usePageContext";
|
||||||
|
import { prefetch } from "vike/client/router";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) {
|
export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { href: string }) {
|
||||||
@ -7,6 +8,8 @@ export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { hr
|
|||||||
const isSameDomain = !(props.href.startsWith("http") || props.href.startsWith("mailto"));
|
const isSameDomain = !(props.href.startsWith("http") || props.href.startsWith("mailto"));
|
||||||
const isDownload = props.href.endsWith(".pdf") || props.href.endsWith(".zip");
|
const isDownload = props.href.endsWith(".pdf") || props.href.endsWith(".zip");
|
||||||
|
|
||||||
|
const handleMouseEnter = () => prefetch(props.href);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a
|
<a
|
||||||
{...props}
|
{...props}
|
||||||
@ -14,6 +17,7 @@ export function Link(props: React.AnchorHTMLAttributes<HTMLAnchorElement> & { hr
|
|||||||
className={clsx(isActive && "is-active", props.className)}
|
className={clsx(isActive && "is-active", props.className)}
|
||||||
{...(isDownload ? { download: true } : {})}
|
{...(isDownload ? { download: true } : {})}
|
||||||
{...(!isSameDomain || isDownload ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
{...(!isSameDomain || isDownload ? { target: "_blank", rel: "noopener noreferrer" } : {})}
|
||||||
|
{...(isSameDomain ? { onMouseEnter: handleMouseEnter } : {})}
|
||||||
>
|
>
|
||||||
{props.children}
|
{props.children}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user