Skip to content

Commit 1f92a42

Browse files
committed
Revert "perf(fonts): Google Fonts 走 next/font/google 自托管,优化 LCP"
This reverts commit 8083d9b.
1 parent caf0d63 commit 1f92a42

2 files changed

Lines changed: 15 additions & 56 deletions

File tree

app/globals.css

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@
1111
--color-accent: #cc0000;
1212
--color-border: var(--foreground);
1313

14-
/*
15-
* 字体链:优先用 next/font/google 生成的自托管 CSS 变量(--font-playfair 等由 app/layout.tsx 注入),
16-
* 一并保留原字面名和系统 fallback,字体加载前浏览器有合理的替身。
17-
*/
18-
--font-serif:
19-
var(--font-playfair), "Playfair Display", "Times New Roman", serif;
20-
--font-body: var(--font-lora), "Lora", Georgia, serif;
21-
--font-sans: var(--font-inter), "Inter", "Helvetica Neue", sans-serif;
22-
--font-mono: var(--font-jb-mono), "JetBrains Mono", "Courier New", monospace;
14+
--font-serif: "Playfair Display", "Times New Roman", serif;
15+
--font-body: "Lora", Georgia, serif;
16+
--font-sans: "Inter", "Helvetica Neue", sans-serif;
17+
--font-mono: "JetBrains Mono", "Courier New", monospace;
2318

2419
--radius-none: 0px;
2520
--radius-sm: 0px;

app/layout.tsx

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// app/layout.tsx
22
import type { Metadata } from "next";
33
import localFont from "next/font/local";
4-
import {
5-
Inter,
6-
JetBrains_Mono,
7-
Playfair_Display,
8-
Lora,
9-
} from "next/font/google";
104
import { RootProvider } from "fumadocs-ui/provider";
115
import Script from "next/script";
126
import "./globals.css";
@@ -32,42 +26,6 @@ const geistMono = localFont({
3226
weight: "100 900",
3327
});
3428

35-
/*
36-
* 四套 Google Fonts 改走 next/font/google 自托管。
37-
* 收益:build 时下载到 .next/static/ 不走 Google CDN,首屏省一次第三方 CSS 往返,
38-
* LCP 下降 200-500ms。自动 font-display: swap + preload + 子集化。
39-
*
40-
* 权重参考原来 <link> CSS URL 里的 weight/style 参数保持一致,避免 fallback 到默认 400。
41-
* display: "swap" — FOUT 代替 FOIT,保证文字立刻可读(避免不可见的 UX 断层)。
42-
* variable 名和 globals.css 里的 --font-* 对齐。
43-
*/
44-
const inter = Inter({
45-
subsets: ["latin"],
46-
weight: ["400", "500", "600", "700"],
47-
variable: "--font-inter",
48-
display: "swap",
49-
});
50-
const jetbrainsMono = JetBrains_Mono({
51-
subsets: ["latin"],
52-
weight: ["400", "500"],
53-
variable: "--font-jb-mono",
54-
display: "swap",
55-
});
56-
const playfair = Playfair_Display({
57-
subsets: ["latin"],
58-
weight: ["400", "600", "700", "900"],
59-
style: ["normal", "italic"],
60-
variable: "--font-playfair",
61-
display: "swap",
62-
});
63-
const lora = Lora({
64-
subsets: ["latin"],
65-
weight: ["400", "600"],
66-
style: ["normal", "italic"],
67-
variable: "--font-lora",
68-
display: "swap",
69-
});
70-
7129
const SITE_URL =
7230
process.env.NEXT_PUBLIC_SITE_URL || "https://involutionhell.com";
7331
const en_description =
@@ -182,10 +140,16 @@ export default async function RootLayout({
182140
return (
183141
<html lang={htmlLang} suppressHydrationWarning>
184142
<head>
185-
{/*
186-
Google Fonts 的 <link> preconnect + stylesheet 已全部改走 next/font/google 自托管,
187-
不再走第三方 CDN(避免阻塞首屏 LCP、也不给 Google 收集 IP)。
188-
*/}
143+
<link rel="preconnect" href="https://fonts.googleapis.com" />
144+
<link
145+
rel="preconnect"
146+
href="https://fonts.gstatic.com"
147+
crossOrigin="anonymous"
148+
/>
149+
<link
150+
rel="stylesheet"
151+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Playfair+Display:ital,wght@0,400;0,600;0,700;0,900;1,400&family=Lora:ital,wght@0,400;0,600;1,400&display=swap"
152+
/>
189153
{/* 主题脚本:避免首屏闪烁 */}
190154
<script
191155
dangerouslySetInnerHTML={{
@@ -274,7 +238,7 @@ export default async function RootLayout({
274238
</head>
275239
<body
276240
suppressHydrationWarning
277-
className={`${geistSans.variable} ${geistMono.variable} ${inter.variable} ${jetbrainsMono.variable} ${playfair.variable} ${lora.variable} antialiased`}
241+
className={`${geistSans.variable} ${geistMono.variable} antialiased`}
278242
>
279243
<div className="site-bg site-bg--stars" aria-hidden />
280244
{/*

0 commit comments

Comments
 (0)