我必须构建一个离子应用程序,我真的需要减少启动时间。 目前,以我的名义6x职业球员,我等待14秒。
我尝试使用
运行我的应用ionic run android --prod
但没有什么不同的附加物。
我使用Ionic v2.1.8
我真的不知道我能做什么,但14秒有点太长了。有人有想法吗?
ps:我在main.ts文件中调用了enableProdMode()。
import { NgModule, enableProdMode } from '@angular/core';
enableProdMode();
我的app.component.ts文件:
import {Component} from '@angular/core';
import {Platform, ViewController, App, AlertController} from 'ionic-angular';
import { StatusBar, Splashscreen } from 'ionic-native';
import {LoginPage} from "../pages/login/login";
import {PData} from "../providers/p-data";
import {CNotification} from "../classes/CNotification";
import {PTranslate} from "../providers/p-translate";
import {CheckUserPage} from "../pages/check-user/check-user";
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = CheckUserPage;
display_handled : boolean = false;
diplayed_notifications_handled: CNotification[] = [];
position : number = 0;
constructor(public platform: Platform, public pdata: PData, public translate: PTranslate, public app: App, public alertCtrl: AlertController) {
platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
});
platform.registerBackButtonAction(() => {
let nav = app.getActiveNav();
let activeView: ViewController = nav.getActive();
if(activeView != null){
if(nav.canGoBack()) {
nav.pop();
} else{
let alert = this.alertCtrl.create({
title: this.translate.get("close-appFine"),
message: this.translate.get("sure-want-leave"),
buttons: [
{
text: this.translate.get("yes"),
role: 'cancel',
},
{
text: this.translate.get("yes"),
handler: () => {
this.platform.exitApp();
}
}
]
});
alert.present();
}
}
});
}
display(range: number = 5) : void {
let keys = this.pdata.keysGetter(this.pdata.notifications_handled).reverse();
let index : number = this.position;
for(index; index < this.position + range && index < keys.length ; index++) {
let guid : string = keys[index];
let notification : CNotification = this.pdata.notifications_handled[guid];
this.diplayed_notifications_handled.push(notification);
}
this.position = index;
this.display_handled = true;
}
doInfinite(infiniteScroll) {
setTimeout(() => {
this.display();
infiniteScroll.complete();
}, 500);
}
}
答案 0 :(得分:0)
我通过更新Ionic v3解决了这个问题,正如Andreas Gassmann所示,实现了延迟加载,如here所示,并使用--prod选项构建。装载时间从12秒以上变为小于4秒。