@xingwangzhe/stalux 1.55.1 → 1.55.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -209,9 +209,15 @@ function initializeClarity(id: string): void {
|
|
|
209
209
|
* Loading is gated on the same signals that mean "first paint is done" instead
|
|
210
210
|
* of `window.load`, which slow third-party resources can postpone forever.
|
|
211
211
|
*/
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
212
|
+
/**
|
|
213
|
+
* GA SDK 只在三个条件之一满足后才加载:首次交互、LCP 后安静期、解析后硬顶。
|
|
214
|
+
* 线上实测 gtag.js 194KB、脚本执行 290ms,若在 LCP 后 600ms 就加载,长任务正好
|
|
215
|
+
* 落在 TBT 统计窗口内。这里把门控整体后移:无交互访客要等到 3.5s 之后,
|
|
216
|
+
* 有交互访客仍然立即加载(统计最完整)。代价是首屏前几秒的行为不计入 GA。
|
|
217
|
+
*/
|
|
218
|
+
const GOOGLE_SDK_FLOOR_MS = 5000;
|
|
219
|
+
const GOOGLE_SDK_LCP_QUIET_MS = 1500;
|
|
220
|
+
const GOOGLE_SDK_CEILING_MS = 10_000;
|
|
215
221
|
let googleSdkStarted = false;
|
|
216
222
|
let googleGateInstalled = false;
|
|
217
223
|
let googleGateOpen = false;
|
|
@@ -16,6 +16,11 @@ const logger = createClientLogger("route-prefetch");
|
|
|
16
16
|
const AFTER_LOAD_DELAY_MS = 1000;
|
|
17
17
|
const LOAD_CEILING_MS = 2500;
|
|
18
18
|
const IDLE_TIMEOUT_MS = 2000;
|
|
19
|
+
/**
|
|
20
|
+
* 首页导航有 6~8 个路由,全量预热在线上实测约 122KB(`/archives/` 单页 48KB)。
|
|
21
|
+
* 只预热导航顺序最靠前的几条,把带宽留给用户当下的交互。
|
|
22
|
+
*/
|
|
23
|
+
const MAX_PREFETCH_ROUTES = 3;
|
|
19
24
|
|
|
20
25
|
export function collectMainRouteUrls(
|
|
21
26
|
documentLike: Pick<Document, "querySelectorAll"> = document,
|
|
@@ -57,7 +62,7 @@ export function mountRoutePrefetch(): (() => void) | undefined {
|
|
|
57
62
|
logger.debug("swup preload API unavailable; skipping route prefetch");
|
|
58
63
|
return;
|
|
59
64
|
}
|
|
60
|
-
const urls = collectMainRouteUrls();
|
|
65
|
+
const urls = collectMainRouteUrls().slice(0, MAX_PREFETCH_ROUTES);
|
|
61
66
|
if (!urls.length) return;
|
|
62
67
|
logger.debug(`prefetching ${urls.length} main routes`);
|
|
63
68
|
// One document at a time: keep the prefetch invisible to the current
|