抖音小程序接入数据预取的方案
- 在抖音官网上的性能优化那里对接的数据预取的问题:
- 项目是使用uni-app框架打包运行的抖音小程序
- 其中${token}是存在Storage里边的,只测试传了一个token,一直报prefetchDetail: 9,prefetchInfo: {mismatchReason: "no prefetch cache"}
- 而且在app.vue里onLanuch的时候token可以打印出来有值的,但是一直报"no prefetch cache"
- 如果在prefetchRules把token写死,就可以预取,只要去本地的就不行,但是本地Storage的token打印是一直有值的
- 猜测方向和疑问:
- 手机在抖音开发者工具真机调试,每次扫码我看在onLAnuch的token都是可以打印出来的。是否跟每次扫码storage的值取不到
- 有没有大佬遇到过的,希望大佬伸出援手帮忙解决一下
这是代码片段:
// app.json ,uni-app打包完需要手动补全数据prefetchRules
"prefetchRules": {
"pages/index/index": {
"https://new-media-1.kureader.com/miniapp/v1/content/home-config": {
"method": "GET",
"header": {
"app-id": "tt91aee7130e98ce1f01",
"authorization": "Bearer ${token}",
"content-type": "application/json",
"project": "reader_paid_dyminiapp"
},
"hitPrefetchExtraRules": {
"requiredHeaderKeys": [
"authorization",
"app-id",
"project",
"content-type"
]
}
}
}
}
// 其中token是存在Storage里边的,只测试传了一个token
// http.ts的参数设置usePrefetchCache为true
{
url,
data,
method: method || 'POST',
header: {
'content-type': contentType,
...header
},
// 主要是开启数据预取
usePrefetchCache: true,
timeout: 10000,
...
}
开启后用真机调试,一直报prefetchDetail: 9,找不到原因,且抖音开发者平台没有解决案例
