fix: 尝试安卓优化

This commit is contained in:
2026-08-02 21:18:51 +08:00
parent 371a7a4582
commit 948a06a55e
4 changed files with 124 additions and 6 deletions

View File

@@ -238,6 +238,34 @@ const preloadNineGridImages = () => {
}
}
/** 安卓专项:把当前 page 的所有图都预热(不创建 DOM仅触发浏览器缓存下载
* 让浏览器在空闲时下载+解码,避免滑到时才下载造成卡顿。
* iOS 不预热,保留原串行体验。 */
const isAndroidClient = (() => {
if (typeof navigator === 'undefined') return false
const ua = navigator.userAgent || ''
return /Android/i.test(ua) && !/CrOS/i.test(ua)
})()
let androidPreloadStarted = false
const preloadAllForAndroid = () => {
if (!isAndroidClient || androidPreloadStarted) return
const urls = [
props.page?.img1,
props.page?.img2,
...(props.page?.images || []),
].filter(Boolean)
if (!urls.length) return
androidPreloadStarted = true
// 错开下载,避免同时抢占首屏网络
urls.forEach((url, i) => {
setTimeout(() => {
const img = new Image()
img.decoding = 'async'
img.src = url
}, 800 + i * 120)
})
}
const runNineSequential = async () => {
const total = (props.page.images || []).length
const { cancelled } = await seq.run({
@@ -378,6 +406,7 @@ watch(
onMounted(() => {
if (!props.nineGridAnimate) preloadNineGridImages()
preloadAllForAndroid()
if (SEQUENTIAL_SELF_TYPES.has(props.page?.type)) bindMultiObserver()
})