|
6 | 6 | <title>TesLongXiao の 主页</title> |
7 | 7 | <link rel="icon" type="image/svg+xml" href="/vite.svg"> |
8 | 8 |
|
9 | | - <!-- DNS 预解析 --> |
10 | | - <link rel="dns-prefetch" href="https://fonts.googleapis.com"> |
11 | | - <link rel="dns-prefetch" href="https://fonts.gstatic.com"> |
12 | | - <link rel="dns-prefetch" href="https://code.iconify.design"> |
13 | | - |
14 | | - <!-- 预连接 --> |
| 9 | + <!-- 预连接关键域名 --> |
15 | 10 | <link rel="preconnect" href="https://fonts.googleapis.com"> |
16 | 11 | <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
| 12 | + <link rel="dns-prefetch" href="https://image-host-for-meta.oss-cn-hangzhou.aliyuncs.com"> |
| 13 | + <link rel="dns-prefetch" href="https://api.teslongxiao.cn"> |
| 14 | + <link rel="dns-prefetch" href="https://cdn.xcnya.cn"> |
17 | 15 |
|
18 | | - <!-- 关键字体预加载 --> |
19 | | - <link rel="preload" href="https://fonts.googleapis.com/css2?family=Archivo:wght@300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&family=Cinzel:wght@400;500;600;700&display=swap" as="style"> |
20 | | - <link href="https://fonts.googleapis.com/css2?family=Archivo:wght@300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&family=Cinzel:wght@400;500;600;700&display=swap" rel="stylesheet"> |
21 | | - |
22 | | - <!-- Iconify Icons - 异步加载 --> |
23 | | - <script async src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js"></script> |
24 | | - |
25 | | - <!-- 内联关键 CSS 防止闪烁 --> |
| 16 | + <!-- 关键 CSS 内联,避免外部请求 --> |
26 | 17 | <style> |
27 | | - * { |
28 | | - margin: 0; |
29 | | - padding: 0; |
30 | | - box-sizing: border-box; |
31 | | - } |
32 | | - |
33 | | - body { |
34 | | - margin: 0; |
35 | | - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', |
36 | | - 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', |
37 | | - sans-serif; |
38 | | - -webkit-font-smoothing: antialiased; |
39 | | - -moz-osx-font-smoothing: grayscale; |
40 | | - background: #0a0e27; |
41 | | - color: #fff; |
42 | | - overflow-x: hidden; |
43 | | - } |
44 | | - |
45 | | - #app { |
46 | | - min-height: 100vh; |
| 18 | + /* 使用系统字体作为后备,避免字体加载阻塞 */ |
| 19 | + :root { |
| 20 | + --font-fallback: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif; |
47 | 21 | } |
| 22 | + </style> |
| 23 | + |
| 24 | + <!-- 字体异步加载 --> |
| 25 | + <script> |
| 26 | + console.log('[Index] HTML 开始解析') |
48 | 27 |
|
49 | | - /* Loading 占位符 */ |
50 | | - .app-loading { |
51 | | - position: fixed; |
52 | | - top: 0; |
53 | | - left: 0; |
54 | | - width: 100vw; |
55 | | - height: 100vh; |
56 | | - background: linear-gradient(180deg, rgba(10, 14, 39, 1) 0%, rgba(26, 31, 58, 1) 50%, rgba(10, 14, 39, 1) 100%); |
57 | | - display: flex; |
58 | | - align-items: center; |
59 | | - justify-content: center; |
60 | | - z-index: 9999; |
| 28 | + // 延迟加载字体,避免阻塞渲染 |
| 29 | + if ('requestIdleCallback' in window) { |
| 30 | + requestIdleCallback(function() { |
| 31 | + var link = document.createElement('link'); |
| 32 | + link.rel = 'stylesheet'; |
| 33 | + link.href = 'https://fonts.googleapis.com/css2?family=Archivo:wght@300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&family=Cinzel:wght@400;500;600;700&display=swap'; |
| 34 | + document.head.appendChild(link); |
| 35 | + }); |
| 36 | + } else { |
| 37 | + setTimeout(function() { |
| 38 | + var link = document.createElement('link'); |
| 39 | + link.rel = 'stylesheet'; |
| 40 | + link.href = 'https://fonts.googleapis.com/css2?family=Archivo:wght@300;400;500;600;700&family=Space+Grotesk:wght@300;400;500;600;700&family=Cinzel:wght@400;500;600;700&display=swap'; |
| 41 | + document.head.appendChild(link); |
| 42 | + }, 100); |
61 | 43 | } |
| 44 | + </script> |
| 45 | + |
| 46 | + <!-- Iconify 图标库 - 立即加载 --> |
| 47 | + <script src="https://code.iconify.design/iconify-icon/1.0.7/iconify-icon.min.js" defer></script> |
| 48 | + |
| 49 | + <!-- 内联关键 CSS 防止闪烁 --> |
| 50 | + <style> |
| 51 | + *{margin:0;padding:0;box-sizing:border-box} |
| 52 | + body{margin:0;font-family:var(--font-fallback);-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;background:#0a0e27;color:#fff;overflow-x:hidden} |
| 53 | + #app{min-height:100vh} |
| 54 | + .app-loading{position:fixed;top:0;left:0;width:100vw;height:100vh;background:linear-gradient(180deg,rgba(10,14,39,1) 0%,rgba(26,31,58,1) 50%,rgba(10,14,39,1) 100%);display:flex;align-items:center;justify-content:center;z-index:9999} |
| 55 | + .app-loading::after{content:'Loading...';font-size:2rem;color:rgba(202,215,255,0.9);animation:pulse 1.5s ease-in-out infinite} |
| 56 | + @keyframes pulse{0%,100%{opacity:0.5}50%{opacity:1}} |
62 | 57 | </style> |
63 | 58 | </head> |
64 | 59 | <body> |
65 | 60 | <div id="app"> |
66 | 61 | <!-- 初始加载占位符 --> |
67 | 62 | <div class="app-loading"></div> |
68 | 63 | </div> |
| 64 | + <script> |
| 65 | + console.log('[Index] 开始加载 main.js') |
| 66 | + console.time('[Index] main.js 加载时间') |
| 67 | + </script> |
69 | 68 | <script type="module" src="/src/main.js"></script> |
| 69 | + <script> |
| 70 | + // 移除 loading 占位符 |
| 71 | + window.addEventListener('load', function() { |
| 72 | + console.timeEnd('[Index] main.js 加载时间') |
| 73 | + console.log('[Index] 窗口完全加载') |
| 74 | + setTimeout(function() { |
| 75 | + var loading = document.querySelector('.app-loading'); |
| 76 | + if (loading) { |
| 77 | + loading.style.transition = 'opacity 0.5s ease'; |
| 78 | + loading.style.opacity = '0'; |
| 79 | + setTimeout(function() { |
| 80 | + loading.remove(); |
| 81 | + console.log('[Index] Loading 占位符已移除') |
| 82 | + }, 500); |
| 83 | + } |
| 84 | + }, 100); |
| 85 | + }); |
| 86 | + </script> |
70 | 87 | </body> |
71 | 88 | </html> |
0 commit comments