

English
Page pre-loading is a performance optimization technology. The preloaded pages can be opened faster.
Platform difference description
App-nvue | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 |
---|---|---|---|---|---|---|
√(2.7.12+) | √(2.7.12+) | x | x | x | x | x |
Attribute | Type | Required | Instruction |
---|---|---|---|
url | string | 是 | 预加载页面url |
success | Function | 否 | 预加载成功完成回调 |
fail | Function | 否 | 预加载失败回调 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
Preload the js file corresponding to /pages/test/test without executing the page pre-rendering logic
uni.preloadPage({url: "/pages/test/test"});
Preload nvue page /pages/test/test
uni.preloadPage({url: "/pages/test/test"});
Precautions
onLoad
and onReady
without triggering onShow
uni.reLanuch
, uni.switchTab
and uni.navigateBack
(including Android return key), the preloaded pages will not be destroyed, and the life cycle onHide
will be triggered onlyuni.redirectTo
on the preloaded page, the preload page will be destroyed, triggering the life cycle onUnload
Example
uni.preloadPage({url: "/pages/test/test"}); // 预加载 /pages/test/test 页面(仅触发onLoad,onReady)
uni.navigateTo({url: "/pages/test/test"}); // url匹配,跳转预加载页面(仅触发onShow)
uni.navigateTo({url: "/pages/test/test?a=b"}); // url不匹配,正常打开新页面
hello uni-app of HBuilderX 2.7.12+ adds a page preload example to the navigator example and the calendar example of uni ui.
Cancel the preload page.
unPreloadPage
, and the life cycle onUnload
will be triggeredunPreloadPage
. However, the preloaded page will no longer exist and will be destroyed as the route changes