ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Speed up initial loading

Open TheMohanraj opened this issue 10 years ago • 159 comments

We're developing an app which is partially native and partially hybrid. We will open cordova activity when user clicks on an menu item and finish the activity when user clicks back. Problem with this approach is, it takes a while to render on the screen for first time. We are hosting all the resource files in the assets folder so caching doesn't make much sense. Is there any progressive way to load the application?

TheMohanraj avatar Jun 06 '16 07:06 TheMohanraj

Hello, I've tested another device:

Nexus 7 (2012) - Android 4.1

Ionic 1 - Starter-App: 4 sec Ionic 2- Conference app: 7 sec Ionic 2 - Starter app: 5.5 sec Ionic 1 - My custom project - 5.5 sec Ionic 2 - My custom project - 8.5 sec

Maybe I can provide this evening another test from an Ulefone-Metal with Android 6.0.

Greetings Graphefruit

graphefruit avatar Dec 19 '16 09:12 graphefruit

After upgrading Ionic to 2.1.17 and running ionic run android --prod significantly improved the performance and my app is starting within 2 to 3 seconds. Don't know what has been changed but I am very happy of it. :smiley:

PrithiviRajG avatar Dec 19 '16 13:12 PrithiviRajG

@PrithiviRajG Could you please share some more information?

  1. How big is your app?
  2. ionic info - Information
  3. package.json - Information
  4. installed plugins / 3rd-party libraries
  5. Which device are you using?
  6. Can you also test it with the starter-app and ionic conference app ? Thanks in advance Graphefruit

graphefruit avatar Dec 19 '16 13:12 graphefruit

@graphefruit

  1. My Apk size is 7MB, size of WWW folder is 7.88MB, plugins folder is 67.1 MB, resources folder is 1.01 MB
  2. ionic info
 ordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.39
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 7
Node Version: v6.7.0
Xcode version: Not installed

  1. package.json
{
  "name": "ionic-app-base",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "build": "ionic-app-scripts build",
    "watch": "ionic-app-scripts watch",
    "serve:before": "watch",
    "emulate:before": "build",
    "deploy:before": "build",
    "build:before": "build",
    "run:before": "build"
  },
  "dependencies": {
    "@angular/common": "2.1.1",
    "@angular/compiler": "2.1.1",
    "@angular/compiler-cli": "2.1.1",
    "@angular/core": "2.1.1",
    "@angular/forms": "2.1.1",
    "@angular/http": "2.1.1",
    "@angular/platform-browser": "2.1.1",
    "@angular/platform-browser-dynamic": "2.1.1",
    "@angular/platform-server": "2.1.1",
    "@ionic/cloud-angular": "0.5.2",
    "@ionic/storage": "1.1.6",
    "angular2-swing": "^0.10.0",
    "ionic-angular": "2.0.0-rc.2",
    "ionic-native": "2.2.3",
    "ionicons": "3.0.0",
    "rxjs": "5.0.0-beta.12",
    "zone.js": "0.6.21"
  },
  "devDependencies": {
    "@ionic/app-scripts": "0.0.39",
    "typescript": "2.0.3"
  }
}

  1. Installed plugins
cordova-plugin-console
cordova-plugin-device
cordova-plugin-facebook4
cordova-plugin-googleplus
cordova-plugin-nativeaudio
cordova-plugin-splashscreen
cordova-plugin-statusbar
cordova-plugin-whitelist
ionic-plugin-keyboard
angular2-swing
  1. Device Information: MOTO G 1st Generation - Android 5.1

  2. will test the start up app and ionic conference shortly and let you know.

PrithiviRajG avatar Dec 19 '16 13:12 PrithiviRajG

@PrithiviRajG Thanks for your information. it looks like you're not on the latest:

Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.2
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.39
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 7
Node Version: v6.7.0
Xcode version: Not installed

-> You're using RC2 not RC4 - also the ionic scripts are now on 0.0.47.

But maybe this is an indication for @jgw96 ?

graphefruit avatar Dec 19 '16 13:12 graphefruit

Hello, I've tested another device:

Ulefone Metal (Android 6.0)

Ionic 1 - Starter-App: 3.5 sec Ionic 2- Conference app: 5 sec Ionic 2 - Starter app: 4.5 - 4.7 sec Ionic 1 - My custom project - 5 sec Ionic 2 - My custom project - 7 sec

Greetings Graphefruit

graphefruit avatar Dec 19 '16 20:12 graphefruit

@mlynch Out of curiosity just want to know that the improving initial load time, will it be fixed part of @danbucholtz current work on tree-shaking OR this will be separate Android specific fix?

I came to know about Dan's work from meeting notes, love working with you guys. Can't believe how much transparent the team is with framework work. :heart:

savanvadalia avatar Dec 22 '16 22:12 savanvadalia

@savanvadalia,

We will never be done trying to make Ionic faster.

Right now we are focused on getting proper tree shaking working and getting closure compiler support. Closure can produce significantly smaller JS bundles than the alternatives resulting in faster load times. We also are investigating code splitting right now to reduce the amount of time needed to load and parse the javascript.

Thanks, Dan

danbucholtz avatar Dec 23 '16 04:12 danbucholtz

@danbucholtz Great to hear this. How can I contribute to the getting-faster features?

I am currently evaluating front-end and mobile technologies for new long-term product lines in the consumer Finance area. Initial loading performance is an essential decision factor.

From recent testing of small-scale app, the iOS/Android performance is acceptable. Browser loading performance is kind of OK too: I will introduce Server Side Rendering later. The most concern lies in the initial loading performance when we start to introduce more pages and third-party modules.

time4Wiley avatar Dec 24 '16 09:12 time4Wiley

Is there any way to show a splash screen or any progress in the inital loading of the Ionic2/Webview app?

They avg. time the app takes to load for me is about 10 seconds. This makes bad user experience when people have to wait about 10 seconds just to load the app. My app isn't big though.

theunreal avatar Dec 26 '16 09:12 theunreal

I use npm run ionic:build --aot and ionic run android --prod to run on device, and the initial time of starter app is about 2 second, but when I use my own project, it comes

Uncaught Error: Cannot find module "./app.module.ngfactory"

I have removed node_modules and www, but it doesn't work. when I just run ionic run android, my project works but the initial time is about 7-8 seconds

here is my ionic info

Cordova CLI: 6.4.0 Ionic Framework Version: 2.0.0-rc.4 Ionic CLI Version: 2.1.18 Ionic App Lib Version: 2.1.9 Ionic App Scripts Version: 0.0.48 ios-deploy version: Not installed ios-sim version: Not installed OS: Windows 10 Node Version: v6.6.0 Xcode version: Not installed

update solved problem by downgrade typescript to "2.0.9"

mattlin4567 avatar Jan 01 '17 06:01 mattlin4567

Whatever I do, deviceready fires after 5 seconds.

barocsi avatar Jan 02 '17 11:01 barocsi

All,

To give an update, we have made significant improvements to the framework itself to improve tree shaking and dead code removal. We have been experimenting with code splitting and closure compiler and have dramatically reduced the bundle size in those cases. Experimenting is the key word and it'll be a bit before we have anything ready for prime time. We are working very closely with the Angular team on this topic.

Closure Compiler is an amazing tool but it can break many 3rd party libs or even your own app if you don't follow the rules, so we're working on creating a simple yet robust and flexible developer experience around this.

Shrinking the bundle size, code splitting and improving launch speed is our #1 priority.

Thanks, Dan

danbucholtz avatar Jan 04 '17 21:01 danbucholtz

@danbucholtz thats great! I suggested closure compiler to Angular CLI team in past. May be a switch could be introduced making compilation using closure compiler optional. Those who have closure compiler friendly code that can enabled it, rest can compile it in a standard way. Ionic team could make sure core Ionic library and Ionic native is fully compatible with closure compiler. BTW would you like to share whats the best launch speed you are able to achieve with/out closure compiler?

naveedahmed1 avatar Jan 04 '17 21:01 naveedahmed1

http://hybridtonative.com, NativeScript is still immature, however it is getting more and more attractive as Ionic issues keep coming, open tickets persisting or growing and webview technology is just spinning around itself, forcing developers work on the technology instead of working with it. Even basic tasks demand huge amount of workarounds, issue digging, requiring a lot of code updating, following changes and updates leaving producion on a muddy base of never ending polishing which is actually bug fixing of bad design choices fixing other bad design choices. At the end of the day we are paying the price and its getting comparable to developing apps natively on both iOS and Android.

barocsi avatar Jan 04 '17 22:01 barocsi

@barocsi hyperbole much? You do realize Angular 2 and ionic are on the cutting edge of the tech they're working with and they are working on finding the best possible course of action for us developers? Also keep in mind that v2 stable has not been released yet.

dylanvdmerwe avatar Jan 05 '17 10:01 dylanvdmerwe

@barocsi If you're not glad with Ionic2 use Ionic1 or write your own angular application. Even with your own angular application you gonna stumble across many issues which ionic solving in their framework already. Also this framework is open source and you can contribute; if you got any problems with the speed they're working on it, or you could fork it and create your own ionic2-fork. I don't want to argue or break something from the fence, even if Ionic2 has a release candidate it just came out from the beta release cyclus. So please give it some time, and if you cant wait take ionic1 and use crosswalk, which has already set some years in this market

graphefruit avatar Jan 05 '17 11:01 graphefruit

Thanks for the suggestions, I am wondering around alternatives for current and future decisions. We already have some robust and heavy Ionic V1 and V2 apps along with and almost 1.5 years of struggling and contributing with issues all over this github repo. Even though this is a pro-ionic thread we must anticipate where this technology is heading, even is something is tagged as cutting edge by @dylanvdmerwe it does not mean it will be subject to persistence by the community and must be honestly evaluated treated with patience as we do, this thread is almost 6 months old, still dealing with an essential and production critical problem.

barocsi avatar Jan 05 '17 11:01 barocsi

I can understand your concerns, thats why I used plain angularjs within my own heavy application. The problem is, that I still stumbled across many issues, because if you're not writing everything yourself or from scratch you'll get there sooner or later. I had big problems with Angular-Material V1 (performance e.g.) and I needed to dig into the framework myself, the rest was written myself in angularjs. But even there I came to the point where performance issues popped up. So I needed to spent time on my "own" framework to find and try to fix them. So I can understand Ionic with their problems, because I fell in these problems myself. Even if they are a big/bigger company they also have limited resources.

The next thing is that Ionic2 isn't just an APP, it also provides a website, it also supports UWP (and thats a lot of pain) and also it supports PWA. So many new features in one framework, that is mostly used for Apps, but supports many other things aswell. With this features there comes a lot of dependencies and much problems when digging into them. But you're concerns are eligible, but I rather see the problems in the complete new technology which was thrown on the market and Ionic tries to grab into them and gets a lot of dependencies with it.

graphefruit avatar Jan 05 '17 11:01 graphefruit

@danbucholtz

Dan, extremely encouraged by your comments re 'experimenting' on code splitting, closure compiler, tree shaking and that launch speed is the current #1 priority for ionic2 (4th Jan). The example ionic2 conference app off Github is a good simple benchmark app that all can use to compare your progress. Hope your work progresses well (and rapidly). Really need a startup time of <=3 secs these days or users are likely to 'go away' - over 6 secs and they definitely 'go away' for good.

Built using --prod and launched on my Nexus 7 (2013) Android 6.0.1 the conference app is currently taking ~8 secs to launch (average timed by stop watch over several launches).

So, still quite a way to go, here's wishing you every success !!! - especially as I really like the structure and facilities provided by ionic2 from an experienced developer's point of view.

Phil

philrob avatar Jan 07 '17 13:01 philrob