首屏优化:scan terminal 加 s-maxage 缓存 + 落地页预加载 API
1. /api/scan/terminal 返回 Cache-Control: public, s-maxage=30, stale-while-revalidate=120 → pre-warm 期间也能返回缓存,白屏 20s 变 1s 2. 落地页 2s 后静默 prefetch /api/cities,预热后端进程和连接池 3. metadata 加 preconnect api.polyweather.top
This commit is contained in:
+10
-1
@@ -1,11 +1,15 @@
|
||||
import type { Metadata } from "next";
|
||||
import { redirect } from "next/navigation";
|
||||
import { PreloadTerminalData } from "@/components/landing/PreloadTerminalData";
|
||||
import { InstitutionalLandingPage } from "@/components/landing/InstitutionalLandingPage";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "PolyWeather | Institutional Weather Signal Intelligence",
|
||||
description:
|
||||
"PolyWeather is a paid professional weather-signal intelligence terminal with METAR evidence, DEB forecast blending, and AI decision cards.",
|
||||
other: {
|
||||
preconnect: "https://api.polyweather.top",
|
||||
},
|
||||
};
|
||||
|
||||
export default async function HomePage({
|
||||
@@ -29,5 +33,10 @@ export default async function HomePage({
|
||||
const qs = usp.toString();
|
||||
redirect(`/auth/callback${qs ? `?${qs}` : ""}`);
|
||||
}
|
||||
return <InstitutionalLandingPage />;
|
||||
return (
|
||||
<>
|
||||
<PreloadTerminalData />
|
||||
<InstitutionalLandingPage />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
|
||||
/**
|
||||
* Warms the backend cache for public API endpoints while the user reads
|
||||
* the landing page, so the first terminal load after login is faster.
|
||||
*
|
||||
* - /api/cities (public, triggers Python process warmup and connection pool init)
|
||||
* - scan terminal (protected — skipped here; prefetched by the terminal
|
||||
* component's stagger loading after login)
|
||||
*/
|
||||
export function PreloadTerminalData() {
|
||||
useEffect(() => {
|
||||
if (typeof window === "undefined" || typeof fetch !== "function") return;
|
||||
|
||||
const controller = new AbortController();
|
||||
|
||||
// Delay 2s so the landing page critical assets load first
|
||||
const t = setTimeout(
|
||||
() =>
|
||||
fetch("/api/cities", {
|
||||
cache: "no-store",
|
||||
headers: { Accept: "application/json" },
|
||||
signal: controller.signal,
|
||||
}).catch(() => {}),
|
||||
2000,
|
||||
);
|
||||
|
||||
return () => {
|
||||
controller.abort();
|
||||
clearTimeout(t);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user