diff --git a/.prefetch b/.prefetch new file mode 100644 index 000000000..76177894d --- /dev/null +++ b/.prefetch @@ -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 diff --git a/app/Http/Controllers/Api/SystemController.php b/app/Http/Controllers/Api/SystemController.php index 4132148cb..5bdfafc1c 100755 --- a/app/Http/Controllers/Api/SystemController.php +++ b/app/Http/Controllers/Api/SystemController.php @@ -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); + } } diff --git a/app/Http/Controllers/IndexController.php b/app/Http/Controllers/IndexController.php index b214e20e2..d6020b77d 100755 --- a/app/Http/Controllers/IndexController.php +++ b/app/Http/Controllers/IndexController.php @@ -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 直接在线预览查看 diff --git a/resources/assets/js/App.vue b/resources/assets/js/App.vue index 7978fb816..90f59e6e0 100755 --- a/resources/assets/js/App.vue +++ b/resources/assets/js/App.vue @@ -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', { diff --git a/resources/assets/js/components/RightBottom.vue b/resources/assets/js/components/RightBottom.vue index bfc9d4d7e..13841b27d 100644 --- a/resources/assets/js/components/RightBottom.vue +++ b/resources/assets/js/components/RightBottom.vue @@ -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;