Speed up top nav with turbo routing and external base CSS.

Remove view-transition lag, swap main content without full reload, prefetch pages, and tear down SSE timers on leave.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-26 20:47:22 +08:00
parent ddfe2a52aa
commit c79bb2ea4b
16 changed files with 865 additions and 548 deletions
+32 -14
View File
@@ -49,14 +49,6 @@
var productCategories = window.PRODUCT_CATEGORIES || [];
var POS_CACHE_KEY = 'qihuo_trading_live_v5';
function runWhenReady(fn) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fn);
} else {
fn();
}
}
function fmtNum(v, digits) {
if (v === null || v === undefined) return '--';
return Number(v).toFixed(digits === undefined ? 2 : digits);
@@ -1595,7 +1587,27 @@
.catch(function () {});
}
runWhenReady(function () {
function cleanupTradePage() {
if (positionSource) {
positionSource.close();
positionSource = null;
}
if (recommendSource) {
recommendSource.close();
recommendSource = null;
}
if (quoteTimer) {
clearTimeout(quoteTimer);
quoteTimer = null;
}
if (calcTimer) {
clearTimeout(calcTimer);
calcTimer = null;
}
}
function bootTradePage() {
if (!list && !orderList) return;
updateCtpConnectButtonState();
setPriceType('limit');
if (isFixedMode() && lotsCalc) {
@@ -1624,14 +1636,20 @@
.then(function (r) { return r.json(); })
.then(function (data) { if (data.ok) renderRecommendations(data); })
.catch(function () {});
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible' && !positionSource) {
connectPositionStream();
}
});
updateSessionUi();
updateRRDisplay();
scheduleQuote();
scheduleAutoCalc();
}
document.addEventListener('visibilitychange', function () {
if (document.visibilityState === 'visible' && list && !positionSource) {
connectPositionStream();
}
});
if (window.qihuoOnPageLoad) window.qihuoOnPageLoad(bootTradePage);
else bootTradePage();
if (window.qihuoOnPageLeave) window.qihuoOnPageLeave(cleanupTradePage);
window.addEventListener('pagehide', cleanupTradePage);
})();