init: 初始化 AssetX 项目仓库
包含 webapp(Next.js 用户端)、webapp-back(Go 后端)、 antdesign(管理后台)、landingpage(营销落地页)、 数据库 SQL 和配置文件。
This commit is contained in:
45
webapp/components/ResourcePreload.tsx
Normal file
45
webapp/components/ResourcePreload.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
"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;
|
||||
}
|
||||
Reference in New Issue
Block a user