web: let next/image serve SVGs so they lazy-load instead of being preloaded

This commit is contained in:
ponas committed 2026-10-15 01:43:05 +02:00
1 parent 8b3150a196
commit fb1453b419
2 files changed
+3 -23

No files matched your search

@@ -43,6 +43,7 @@ export const ContactEntityBlock = ({
<img <img
src="/assets/graphics/portrait-pig.svg" src="/assets/graphics/portrait-pig.svg"
className={styles.portraitPlaceholder} className={styles.portraitPlaceholder}
loading="lazy"
/> />
)} )}
{image && ( {image && (
+2 -23
View File
@@ -7,27 +7,6 @@ type ImageProps = NextImageProps & {
imageFormat?: string | null; // "original" | "bleed" | "fullWidth" imageFormat?: string | null; // "original" | "bleed" | "fullWidth"
}; };
function isSvgSrc(src: NextImageProps["src"]): src is string {
return typeof src === "string" && /\.svg(\?|#|$)/i.test(src);
}
function MaybeNextImage(props: NextImageProps) {
if (isSvgSrc(props.src)) {
const { src, alt, width, height, className, style } = props;
return (
<img // eslint-disable-line @next/next/no-img-element
src={src}
alt={alt}
width={width}
height={height}
className={className}
style={style}
/>
);
}
return <NextImage {...props} />;
}
export function ImageFigure(props: ImageProps) { export function ImageFigure(props: ImageProps) {
const { attribution, caption, imageFormat, ...imageProps } = props; const { attribution, caption, imageFormat, ...imageProps } = props;
return ( return (
@@ -35,7 +14,7 @@ export function ImageFigure(props: ImageProps) {
className={`${styles.image} ${imageFormat ? styles[imageFormat] : ""}`} className={`${styles.image} ${imageFormat ? styles[imageFormat] : ""}`}
> >
<div className={styles.imageWrapper}> <div className={styles.imageWrapper}>
<MaybeNextImage quality={90} {...imageProps} /> <NextImage quality={90} {...imageProps} />
{attribution && <div className={styles.attribution}>{attribution}</div>} {attribution && <div className={styles.attribution}>{attribution}</div>}
</div> </div>
{caption && <figcaption>{caption}</figcaption>} {caption && <figcaption>{caption}</figcaption>}
@@ -44,5 +23,5 @@ export function ImageFigure(props: ImageProps) {
} }
export function Image(props: NextImageProps) { export function Image(props: NextImageProps) {
return <MaybeNextImage {...props} />; return <NextImage {...props} />;
} }