Delay on application startup

Asked

Viewed 876 times

2

I created a cross-platform application using Ionic 2 + Angular 2 according to the Get Started of ionic documentation. The basic command to create a project with side menu is this way below:

$ionic start myApp sidemenu

There is something that is bothering us a lot: the application’s startup, on the Android platform, which today is taking around 14 (mega, master, hyper, ultra) seconds (the Rubens Barrichello would do 5 laps in the Circuit of Monaco).

I did some research and found something saying that happens when the app is in mode debug, but I managed a version of release and is still slow on startup. I tested on IOS and the loading speed is very fast, which would normally happen. Has anyone ever come across this? Is there any setting that needs to be performed to resolve the problem?

  • Have you tried putting the following code on main.ts? enableProdMode();

  • @Diegoaugusto but what would be the justification? I will try to see here.

  • It disables hotdeploy, meaning you won’t be listening to code changes and reloading them

  • Another question, you haven’t made any changes yet in the template that was downloaded? Or is making your app on top of it?

  • @Diegoaugusto already tried yes but without success! It’s still slow. I’m doing on top of the application that was generated from Starter.

  • All right, so you’ve got enough modules right? You’re loading them all into app.module.ts?

  • @Diegoaugusto yes, I am loading everything in app.moodule.ts. hehe

Show 2 more comments

1 answer

4


To improve the performance of your app you can use a ancient secret technique calling for LazyLoading (Lazy cargo). No Ionic the application of this model consists of loading the necessary modules for each page at the time of loading, avoiding loading all modules, providers, etc at the beginning of the app.

Let’s assume you have one component/page calling for home, i would have the following file structure:

home.ts
home.scss
home.html

To implement Lazy you need to create another file, which is the file that will import what you need.

home.module.ts

To use the lazy it is also necessary to make some adjustments, in your file home.ts you need to use the Developer @IonicPage(). Example:

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class Home {}

Already in your home.module.ts file:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Home } from './home';

@NgModule({
  declarations: [
    Home,
  ],
  imports: [
    IonicPageModule.forChild(Home),
  ],
  exports: [
    Home
  ]
})
export class HomeModule {}

When you call your page Home, consecutively the HomeModule will be called and the same will load your components.

An important thing, you no longer need to use the imported Component to do the routing, you just need to pass the string with the same name, example: this.nav.push('Home');

Note, you can import your providers tbm in home.module.ts, just add the attribute providers: [] in the structure of NgModule

  • So you’ve been through it and solved the problem like that?! It makes a lot of sense what you’re saying. I’ll take a test and tell you. From now on, thank you.

  • Yes, I was able to reduce the startup time of the app considerably.

  • Man, it took me a while to adjust everything but it was. But it didn’t get that much better. I thought that white screen at first would practically disappear. huehuhe... but I’m still missing some performance. You’d have another tip ?!

  • Ever tried compiling for production? Ionic Cordova run android --Prod --release

  • I did this before I even made the change you suggested. Ai had slowed down a bit. Now I haven’t tried compiling as Prod yet. I’ll do it and warn you.,

  • Beauty! Try to see if it improves

  • I’ll validate your answer, but for me there must still be something else. Whether or not Lazyloading’s strategy works, but my case still wanted a little more performance. There’s something wrong with my code maybe. Vlw. If you suspect anything, let me know. hehe

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.