From cc8e818142fa68786fb91b63ffd549c354cfe51a Mon Sep 17 00:00:00 2001 From: MengYX Date: Tue, 11 Feb 2020 16:35:45 +0800 Subject: [PATCH] Optimize Loading --- src/component/preview.vue | 7 +++---- src/component/upload.vue | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/component/preview.vue b/src/component/preview.vue index 44191f3..0395a08 100644 --- a/src/component/preview.vue +++ b/src/component/preview.vue @@ -10,18 +10,17 @@ - - + - + - + diff --git a/src/component/upload.vue b/src/component/upload.vue index d37be77..ce3c348 100644 --- a/src/component/upload.vue +++ b/src/component/upload.vue @@ -27,14 +27,19 @@ }, mounted() { if (document.location.host !== "" && process.env.NODE_ENV === 'production') { - const worker = require("workerize-loader!../decrypt/common"); this.thread_num = navigator.hardwareConcurrency || 1; - for (let i = 0; i < this.thread_num; i++) { - //todo: Optimize for first loading - // noinspection JSValidateTypes,JSUnresolvedVariable - this.workers.push(worker().CommonDecrypt); - this.idle_workers.push(i); - } + const worker = require("workerize-loader!../decrypt/common"); + // noinspection JSValidateTypes,JSUnresolvedVariable + this.workers.push(worker().CommonDecrypt); + this.idle_workers.push(0); + // delay to optimize for first loading + setTimeout(() => { + for (let i = 1; i < this.thread_num; i++) { + // noinspection JSValidateTypes,JSUnresolvedVariable + this.workers.push(worker().CommonDecrypt); + this.idle_workers.push(i); + } + }, 1000); } else { const dec = require('../decrypt/common'); this.workers.push(dec.CommonDecrypt);