【问题标题】:Ionic 2 : Reduce app boot timeIonic 2:减少应用启动时间
【发布时间】:2017-12-02 00:20:29
【问题描述】:

我必须构建一个 ionic 应用程序,我确实需要减少启动时间。 目前,以我的荣誉 6x pro 我等待 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);
  }
}

【问题讨论】:

  • 能否请您添加您的app.component.ts 文件的内容?所以我们可以看看应用启动时发生了什么...
  • 帖子已更新。但我不知道为什么它很重要?
  • 提供您的离子信息输出。是否可以将您的 Ionic 版本升级到新版本?它目前已经在 3.4.0 中,使用 Angular 4(我猜 2.1 仍在使用 Angular 2,它没有一些改进)。
  • 当然,我已经考虑过了。但我担心升级会干扰我所有的应用程序。
  • 如果您升级到 Ionic v3,您可以为您的应用添加延迟加载。这应该会进一步提高加载速度,但它需要在您的应用中进行大量更改。

标签: android ios mobile ionic2 splash-screen


【解决方案1】:

我通过更新 Ionic v3 解决了这个问题,正如 Andreas Gassmann 所指出的那样,实现了延迟加载,如 here 所示,并使用 --prod 选项进行构建。设备加载时间从12s多到4s不到。

【讨论】:

    猜你喜欢
    • 2017-05-11
    • 1970-01-01
    • 2018-04-12
    • 2016-10-25
    • 2011-05-12
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多