mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-27 14:07:50 +00:00
perf: 优化预加载资源
This commit is contained in:
parent
50a1a3147e
commit
57e422f2d3
22
.prefetch
Normal file
22
.prefetch
Normal file
@ -0,0 +1,22 @@
|
||||
office/web-apps/apps/api/documents/api.js?hash={version}
|
||||
office/7.5.1-23/sdkjs/cell/css/main.css
|
||||
office/7.5.1-23/web-apps/apps/spreadsheeteditor/main/resources/css/app.css
|
||||
office/7.5.1-23/web-apps/vendor/requirejs/require.js
|
||||
office/7.5.1-23/web-apps/apps/spreadsheeteditor/main/app.js
|
||||
office/7.5.1-23/sdkjs/common/AllFonts.js
|
||||
office/7.5.1-23/web-apps/vendor/xregexp/xregexp-all-min.js
|
||||
office/7.5.1-23/web-apps/vendor/socketio/socket.io.min.js
|
||||
office/7.5.1-23/sdkjs/cell/sdk-all-min.js
|
||||
office/7.5.1-23/sdkjs/cell/sdk-all.js
|
||||
office/7.5.1-23/sdkjs/common/libfont/engine/fonts.js
|
||||
office/7.5.1-23/sdkjs/common/Charts/ChartStyles.js
|
||||
office/7.5.1-23/sdkjs/common/libfont/engine/fonts.wasm
|
||||
office/7.5.1-23/web-apps/apps/presentationeditor/main/resources/css/app.css
|
||||
office/7.5.1-23/web-apps/apps/presentationeditor/main/app.js
|
||||
office/7.5.1-23/sdkjs/slide/sdk-all-min.js
|
||||
office/7.5.1-23/sdkjs/slide/sdk-all.js
|
||||
office/7.5.1-23/sdkjs/slide/themes//themes.js
|
||||
office/7.5.1-23/web-apps/apps/documenteditor/main/resources/css/app.css
|
||||
office/7.5.1-23/web-apps/apps/documenteditor/main/app.js
|
||||
office/7.5.1-23/sdkjs/word/sdk-all-min.js
|
||||
office/7.5.1-23/sdkjs/word/sdk-all.js
|
||||
@ -1276,8 +1276,14 @@ class SystemController extends AbstractController
|
||||
* @apiGroup system
|
||||
* @apiName version
|
||||
*
|
||||
* @apiSuccess {String} version
|
||||
* @apiSuccess {String} publish
|
||||
* @apiSuccessExample {json} Success-Response:
|
||||
{
|
||||
"version": "0.0.1",
|
||||
"publish": {
|
||||
"provider": "generic",
|
||||
"url": ""
|
||||
}
|
||||
}
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
@ -1299,4 +1305,38 @@ class SystemController extends AbstractController
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {get} api/system/prefetch 25. 预加载的资源
|
||||
*
|
||||
* @apiVersion 1.0.0
|
||||
* @apiGroup system
|
||||
* @apiName prefetch
|
||||
*
|
||||
* @apiSuccessExample {array} Success-Response:
|
||||
[
|
||||
"https://......",
|
||||
"https://......",
|
||||
"......",
|
||||
]
|
||||
*/
|
||||
public function prefetch()
|
||||
{
|
||||
$file = base_path('.prefetch');
|
||||
if (!file_exists($file)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$version = Base::getVersion();
|
||||
$content = file_get_contents($file);
|
||||
|
||||
$array = explode("\n", $content);
|
||||
$array = array_values(array_filter($array));
|
||||
|
||||
return array_map(function($item) use ($version) {
|
||||
$url = trim($item);
|
||||
$url = str_replace('{version}', $version, $url);
|
||||
return url($url);
|
||||
}, $array);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,14 +38,8 @@ class IndexController extends InvokeController
|
||||
if ($action) {
|
||||
$app .= "__" . $action;
|
||||
}
|
||||
switch ($app) {
|
||||
case 'manifest.txt':
|
||||
$app = 'manifest';
|
||||
$child = 'txt';
|
||||
break;
|
||||
|
||||
case 'default':
|
||||
return '';
|
||||
if ($app == 'default') {
|
||||
return '';
|
||||
}
|
||||
if (!method_exists($this, $app)) {
|
||||
$app = method_exists($this, $method) ? $method : 'main';
|
||||
@ -74,49 +68,7 @@ class IndexController extends InvokeController
|
||||
'version' => Base::getVersion(),
|
||||
'style' => $style,
|
||||
'script' => $script,
|
||||
])->header('Link', "<" . url('manifest.txt') . ">; rel=\"prefetch\"");
|
||||
}
|
||||
|
||||
/**
|
||||
* Manifest
|
||||
* @param $child
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response|string
|
||||
*/
|
||||
public function manifest($child = '')
|
||||
{
|
||||
if (empty($child)) {
|
||||
$murl = url('manifest.txt');
|
||||
return response($murl)->header('Link', "<{$murl}>; rel=\"prefetch\"");
|
||||
}
|
||||
$array = [
|
||||
"office/web-apps/apps/api/documents/api.js?hash=" . Base::getVersion(),
|
||||
"office/7.5.1-23/web-apps/vendor/requirejs/require.js",
|
||||
"office/7.5.1-23/web-apps/apps/api/documents/api.js",
|
||||
"office/7.5.1-23/sdkjs/common/AllFonts.js",
|
||||
"office/7.5.1-23/web-apps/vendor/xregexp/xregexp-all-min.js",
|
||||
"office/7.5.1-23/web-apps/vendor/sockjs/sockjs.min.js",
|
||||
"office/7.5.1-23/web-apps/vendor/jszip/jszip.min.js",
|
||||
"office/7.5.1-23/web-apps/vendor/jszip-utils/jszip-utils.min.js",
|
||||
"office/7.5.1-23/sdkjs/common/libfont/wasm/fonts.js",
|
||||
"office/7.5.1-23/sdkjs/common/Charts/ChartStyles.js",
|
||||
"office/7.5.1-23/sdkjs/slide/themes//themes.js",
|
||||
|
||||
"office/7.5.1-23/web-apps/apps/presentationeditor/main/app.js",
|
||||
"office/7.5.1-23/sdkjs/slide/sdk-all-min.js",
|
||||
"office/7.5.1-23/sdkjs/slide/sdk-all.js",
|
||||
|
||||
"office/7.5.1-23/web-apps/apps/documenteditor/main/app.js",
|
||||
"office/7.5.1-23/sdkjs/word/sdk-all-min.js",
|
||||
"office/7.5.1-23/sdkjs/word/sdk-all.js",
|
||||
|
||||
"office/7.5.1-23/web-apps/apps/spreadsheeteditor/main/app.js",
|
||||
"office/7.5.1-23/sdkjs/cell/sdk-all-min.js",
|
||||
"office/7.5.1-23/sdkjs/cell/sdk-all.js",
|
||||
];
|
||||
foreach ($array as &$item) {
|
||||
$item = url($item);
|
||||
}
|
||||
return implode(PHP_EOL, $array);
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -369,7 +321,7 @@ class IndexController extends InvokeController
|
||||
$browser = 'none';
|
||||
if (str_contains($userAgent, 'chrome')) {
|
||||
$browser = str_contains($userAgent, 'android') || str_contains($userAgent, 'harmonyos') ? 'android-mobile' : 'chrome-desktop';
|
||||
} elseif (str_contains($userAgent, 'safari')) {
|
||||
} elseif (str_contains($userAgent, 'safari') || str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad')) {
|
||||
$browser = str_contains($userAgent, 'iphone') || str_contains($userAgent, 'ipad') ? 'safari-mobile' : 'safari-desktop';
|
||||
}
|
||||
// electron 直接在线预览查看
|
||||
|
||||
@ -281,7 +281,6 @@ export default {
|
||||
this.$Electron.registerMsgListener('browserWindowFocus', _ => {
|
||||
this.$store.state.windowActive = true;
|
||||
})
|
||||
$A.loadIframe($A.apiUrl("../manifest")).catch(_ => {})
|
||||
$A.bindScreenshotKey(this.$store.state.cacheKeyboard);
|
||||
//
|
||||
this.$Electron.sendMessage('setMenuLanguage', {
|
||||
|
||||
@ -67,6 +67,7 @@ export default {
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.prefetchResources()
|
||||
this.checkVersion()
|
||||
//
|
||||
if (this.$Electron) {
|
||||
@ -117,6 +118,34 @@ export default {
|
||||
return this.$isSoftware && (apiHome == "" || apiHome == "public")
|
||||
},
|
||||
|
||||
prefetchResources() {
|
||||
if (this.isNotServer()) {
|
||||
return;
|
||||
}
|
||||
if (this.$Electron && $A.$isSubElectron) {
|
||||
return; // 客户端子窗口 不预加载
|
||||
}
|
||||
if (this.$isEEUiApp) {
|
||||
return; // 移动端 不预加载
|
||||
}
|
||||
axios.get($A.apiUrl('system/prefetch')).then(({status, data}) => {
|
||||
if (status === 200) {
|
||||
data.forEach(url => {
|
||||
const script = document.createElement('link')
|
||||
script.rel = 'prefetch'
|
||||
script.href = url
|
||||
script.onload = () => {
|
||||
document.head.removeChild(script)
|
||||
}
|
||||
script.onerror = () => {
|
||||
document.head.removeChild(script)
|
||||
}
|
||||
document.head.appendChild(script)
|
||||
})
|
||||
}
|
||||
}).catch(_ => { })
|
||||
},
|
||||
|
||||
checkVersion() {
|
||||
if (this.isNotServer()) {
|
||||
return;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user