Comments (8)
中间利用的是小程序页面实例化的时间差,不管怎样,请求都是被提前发起了,必然会起到优化效果
from wxpage.
一般预加载是使用提前生成Promise实例执行加载流程,只要在Promise的回调后就不需要关心异步逻辑是进行中 or 完成
from wxpage.
一般预加载是使用提前生成Promise实例执行加载流程,只要在Promise的回调后就不需要关心异步逻辑是进行中 or 完成
稍微有点不明白,我需要在哪里执行Promise?第一个页面还是第二个页面?有相关的示例代码吗?
from wxpage.
// 页面index
Page.P('index', {
clickToDetail() {
this.$preload('detail')
}
})
// 页面detail
Page.P('detail', {
onPreload() {
this.$put('detail_preload_fetch', this.fetch())
},
onLoad() {
;(this.$take('detail_preload_fetch')||this.fetch()).then(data=>{
console.log(data)
// do somthing
})
},
fetch() {
return fetch('xxx')
}
})
from wxpage.
嗯嗯,终于明白了,谢谢大侠!
但是这样的话,其实还是存在一个问题,就是还是有可能this.$take('detail_preload_fetch')暂时还没有数据,那这样的话就执行的是this.fetch()的返回数据。如果是这样,那么本次跳转其实就没有达到预加载的效果,对吧?当然这个要看网络情况,如果网络良好,多半跳转还是能够在onLoad时拿到缓存数据的。不知道我理解的有问题吗?
from wxpage.
中间利用的是小程序页面实例化的时间差,不管怎样,请求都是被提前发起了,必然会起到优化效果
这样理解也对,嗯。感谢。
from wxpage.
文档不是讲$preload的数据不一定会被用到 这种预加载的数据一般会保存在storage内,因为用户不一定会马上访问页面,而把数据存在全局变量会增加小程序占用的内存。微信会毫不犹豫的把内存占用过大的小程序给杀掉 如果这样的话 put take 就不适用了吧
from wxpage.
文档不是讲$preload的数据不一定会被用到 这种预加载的数据一般会保存在storage内,因为用户不一定会马上访问页面,而把数据存在全局变量会增加小程序占用的内存。微信会毫不犹豫的把内存占用过大的小程序给杀掉 如果这样的话 put take 就不适用了吧
这就需要你的判断了,我的页面大多是消息页用户需要停留一段时间,这个时间我就会把页面可以触及的链接给预加载了,而在当前页面的unload中我又注册了一个清除所有子页面预加载数据的逻辑。这样的话能有效减少页面的内存占用。
from wxpage.
Related Issues (20)
- 小程序体验提示存在定时器未跟随页面回收 HOT 5
- this.$cache方法中不能调用$route么? HOT 1
- 支持分包配置么? HOT 10
- this.$setData()不支持回调? HOT 2
- this.$cache怎么删除缓存 HOT 1
- 大大能否考虑添加typescript支持呢 HOT 1
- 个人原因 HOT 4
- 请问extendPageBefore和extendPageAfter的区别以及注意事项? HOT 1
- $session 之类的辅助函数能否单独引用 HOT 1
- 关于npm引入wxpage在小程序里使用的问题 HOT 18
- onAppShow只执行一次 HOT 5
- 请问这段代码是什么意思啊?完全看不懂 HOT 2
- 库中无用代码的优化 HOT 9
- QQ小程序截至0.1.27版本仍需要补全页面json HOT 7
- 请问,有木有跨级多层组件的通讯,props传递的方案呀 HOT 2
- session的疑问 HOT 3
- queue函数的疑问 HOT 2
- component.js函数的疑问
- $name 和 $curPageName() 的疑问
- 希望大神有时间修改下,跳转有时失效的问题 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wxpage.