Files
assetx/webapp/components/ResourcePreload.tsx
default 2ee4553b71 init: 初始化 AssetX 项目仓库
包含 webapp(Next.js 用户端)、webapp-back(Go 后端)、
antdesign(管理后台)、landingpage(营销落地页)、
数据库 SQL 和配置文件。
2026-03-27 11:26:43 +00:00

46 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client";
import { useEffect } from 'react';
// 预加载关键资源
const criticalResources = [
// 导航图标
'/icons/navigation/icon-lending.svg',
'/icons/navigation/icon-alp.svg',
'/icons/navigation/icon-swap.svg',
'/icons/navigation/icon-transparency.svg',
'/icons/navigation/icon-points.svg',
// 常用操作图标
'/icons/actions/icon-wallet.svg',
'/icons/actions/icon-notification.svg',
'/icons/actions/icon-copy.svg',
// Logo
'/logos/logo.svg',
];
export default function ResourcePreload() {
useEffect(() => {
// 使用浏览器原生预加载API
criticalResources.forEach(url => {
const link = document.createElement('link');
link.rel = 'prefetch';
link.as = 'image';
link.href = url;
document.head.appendChild(link);
});
// 可选使用fetch预加载并缓存
if ('caches' in window) {
caches.open('svg-cache-v1').then(cache => {
cache.addAll(criticalResources).catch(err => {
console.error('预加载SVG失败:', err);
});
});
}
}, []);
return null;
}