diff --git a/components/LazyImage.js b/components/LazyImage.js index 3c8c2227..cf78ba5d 100644 --- a/components/LazyImage.js +++ b/components/LazyImage.js @@ -4,15 +4,15 @@ import React, { useEffect, useRef, useState } from 'react' * 默认懒加载占位图 */ const loadingSVG = ( - + ) /** @@ -20,7 +20,18 @@ const loadingSVG = ( * @param {*} param0 * @returns */ -export default function LazyImage({ id, src, alt, placeholderSrc = loadingSVG, className, width, height, onLoad, style }) { +export default function LazyImage({ + priority, + id, + src, + alt, + placeholderSrc = loadingSVG, + className, + width, + height, + onLoad, + style +}) { const imageRef = useRef(null) const [imageLoaded, setImageLoaded] = useState(false) @@ -31,6 +42,17 @@ export default function LazyImage({ id, src, alt, placeholderSrc = loadingSVG, c } } + // 预加载图片 + useEffect(() => { + if (priority) { + const link = document.createElement('link') + link.rel = 'preload' + link.as = 'image' + link.href = src + document.head.appendChild(link) + } + }, [priority, src]) + useEffect(() => { const observer = new IntersectionObserver( (entries) => { diff --git a/themes/heo/components/BlogPostCard.js b/themes/heo/components/BlogPostCard.js index 03cb4860..756743dd 100644 --- a/themes/heo/components/BlogPostCard.js +++ b/themes/heo/components/BlogPostCard.js @@ -3,7 +3,6 @@ import CONFIG from '../config' import BLOG from '@/blog.config' import TagItemMini from './TagItemMini' import LazyImage from '@/components/LazyImage' -// import Image from 'next/image' const BlogPostCard = ({ index, post, showSummary, siteInfo }) => { const showPreview = CONFIG.POST_LIST_PREVIEW && post.blockMap @@ -20,7 +19,7 @@ const BlogPostCard = ({ index, post, showSummary, siteInfo }) => { {showPageCover && (