Skip to content

Commit 40d4a04

Browse files
committed
更新[BoxJs TF]: 优化首页渲染速度, 感谢 eslint 大佬提供帮助
1 parent c7bb0cc commit 40d4a04

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎box/chavy.boxjs.html‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
11771177
'https://raw.githubusercontent.com/Orz-3/task/master/appstore.png'
11781178
]
11791179
},
1180+
boxServerData: null,
11801181
box: null
11811182
}
11821183
},
@@ -1621,8 +1622,12 @@ <h2 :class="version === ver.version ? 'primary--text' : undefined">v{{ver.versio
16211622
}
16221623
// 监听浏览器后退事件
16231624
window.addEventListener('popstate', () => (this.path = path), false)
1624-
// 获取 BoxJs 数据, 取到数据再渲染页面
1625-
await axios.get('/query/boxdata').then((resp) => (this.box = resp.data))
1625+
// 如果后端没有渲染数据, 则发出请求获取数据
1626+
if (this.boxServerData) {
1627+
this.box = this.boxServerData
1628+
} else {
1629+
await axios.get('/query/boxdata').then((resp) => (this.box = resp.data))
1630+
}
16261631
// 获取全局备份
16271632
if (this.view === 'bak') {
16281633
await this.loadGlobalBak()

‎box/chavy.boxjs.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const $ = new Env('BoxJs')
22

3-
$.version = '0.7.27'
3+
$.version = '0.7.28'
44
$.versionType = 'beta'
55

66
/**
@@ -130,13 +130,16 @@ async function handlePage() {
130130
await $.http.get($.web).then(
131131
(resp) => {
132132
if (/<title>BoxJs<\/title>/.test(resp.body)) {
133+
// 返回页面源码, 并马上存储到持久化仓库
133134
$.html = resp.body
134135
const cache = { version: $.version, cache: $.html }
135136
$.setjson(cache, $.KEY_web_cache)
136137
} else {
138+
// 如果返回的页面源码不是预期的, 则从持久化仓库中获取
137139
$.html = $.getjson($.KEY_web_cache).cache
138140
}
139141
},
142+
// 如果获取页面源码失败, 则从持久化仓库中获取
140143
() => ($.html = $.getjson($.KEY_web_cache).cache)
141144
)
142145
}
@@ -147,6 +150,13 @@ async function handlePage() {
147150
} else if (theme === 'dark') {
148151
$.html = $.html.replace('#fff', '#121212')
149152
}
153+
/**
154+
* 后端渲染数据, 感谢 https://t.me/eslint 提供帮助
155+
*
156+
* 如果直接渲染到 box: null 会出现双向绑定问题
157+
* 所以先渲染到 `boxServerData: null` 再由前端 `this.box = this.boxServerData` 实现双向绑定
158+
*/
159+
$.html = $.html.replace('boxServerData: null', 'boxServerData:' + JSON.stringify(getBoxData()))
150160
}
151161

152162
/**

‎box/release/box.release.tf.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
{
22
"releases": [
3+
{
4+
"version": "0.7.28",
5+
"tags": ["beta"],
6+
"author": "@chavyleung",
7+
"icon": "https://avatars3.githubusercontent.com/u/29748519",
8+
"repo": "https://github.com/chavyleung",
9+
"notes": [
10+
{
11+
"name": "优化",
12+
"descs": ["数据后端渲染", "更快更平顺的首页加载", "不闪屏了"]
13+
},
14+
{
15+
"name": "感谢",
16+
"descs": ["感谢 @eslint 大佬提供帮助"]
17+
}
18+
]
19+
},
320
{
421
"version": "0.7.27",
522
"tags": ["beta"],

0 commit comments

Comments
 (0)