Speed up initial loading
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?
How big are your bundles? Are you using lots of third party libraries?
Thanks, Dan
Hi Dan!
Nothing too crazy I think.
My bundle size using webpack and AoT is 1.9MB.
Deps in package.json
...
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@biesbjerg/ng2-translate-po-loader": "^0.1.3",
"@ionic/app-scripts": "0.0.46",
"@ionic/storage": "1.1.6",
"@ngrx/core": "1.2.0",
"@ngrx/effects": "2.0.0",
"@ngrx/store": "2.2.1",
"angular2-uuid": "1.1.0",
"ionic-angular": "nightly",
"ionic-native": "2.2.7",
"ionicons": "3.0.0",
"ng2-translate": "^4.1.0",
"ngrx-store-freeze": "0.1.4",
"ngrx-store-logger": "0.1.7",
"pofile": "^1.0.2",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@biesbjerg/ng2-translate-extract": "^0.1.1",
"@ionic/app-scripts": "0.0.46",
"@types/cordova-plugin-media": "0.0.3",
"del": "^2.2.2",
"fs": "0.0.1-security",
"path": "^0.12.7",
"typescript": "2.0.10"
},
"cordovaPlugins": [
"cordova-plugin-device",
"cordova-plugin-console",
"cordova-plugin-whitelist",
"cordova-plugin-splashscreen",
"cordova-plugin-statusbar",
"ionic-plugin-keyboard",
"cordova-plugin-globalization",
"cordova-plugin-media",
"cordova-plugin-file",
"cordova-plugin-compat",
{
"locator": "https://github.com/EddyVerbruggen/cordova-plugin-backgroundaudio",
"id": "nl.x-services.plugins.backgroundaudio"
},
"cordova-plugin-app-version",
"cordova-plugin-x-socialsharing",
{
"locator": "https://github.com/biesbjerg/cordova-plugin-inapppurchase.git",
"id": "cordova-plugin-inapppurchase"
},
{
"locator": "https://github.com/driftyco/cordova-plugin-wkwebview-engine.git",
"id": "cordova-plugin-wkwebview-engine"
},
"cordova-plugin-google-analytics",
"cordova-sqlite-storage"
],
...
Hello, I would like to share my own information with the startup time aswell. Actually I'm putting my old Ionic V1 to V2 (rewriting everything from scratch).
My old application with crosswalk starts up (depending on device) from 3 to 4 seconds. The new application needs 6 to 7 seconds (7 seconds are more likely).
I've tried the RC3 aswell as the nightly build (Ionic Framework Version: 2.0.0-rc.3-201612021933)
Package.json:
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/storage": "1.1.6",
"ionic-angular": "^2.0.0-rc.3-201612021933",
"ionic-native": "2.2.3",
"ionicons": "3.0.0",
"moment": "2.15.1",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "0.0.44",
"typescript": "2.0.9",
"webpack-bundle-analyzer": "^1.5.3"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [],
"description": "o2: An Ionic project"
}
My assets folder (third party plugins / images) is about 2.14 MB. I'm using 6 different third-party plugins (jQuery, moment, hammer, jquery 3.1, fullcalendar, svg-panzoom, fontawesome).
The APK-Size is: 6.58 MB Unzipped this package is: 15 MB.
Folding:
- assets : 10.1 MB -> www/assets : 2.93 MB -> www/build: 7.07 MB -> www/build/main.js: 3.003 MB -> www/build/main.js.map: 3.790 MB (is this needed on production?)
- res: 1.73 MB
- class.dex: 3.07 MB
- resources.arsx: 0.13 MB
Ionic-Version information:
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3-201612021933
Ionic CLI Version: 2.1.13
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.44
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 8.1
Node Version: v6.9.1
Xcode version: Not installed
Maybe it helps, if you @danbucholtz / @jgw96 could use my actual project to debug this problem I'd be happy to share it (private).
Greetings Graphefruit
I believe sourcemaps should be disabled for production build. Angular CLi recently added an option to disable it https://github.com/angular/angular-cli/pull/3262
Graphefruit can you please also share the number of components and directive your app have?
Hello @naveedahmed1, here we go:
- services: 10
- pipes: 3
- pages: ~49
- custom-config: 1
- directives: 0 ( ;) )
Greetings Graphefruit
@naveedahmed1 That issue is about not inlining sourcemaps, which I agree probably isn't the best idea in production. However, external map files for production assets can be useful and only add a small comment to the deployed files. I'd definitely like to be able to generate external map files for production builds.
@rob3c,
It will be configurable.
Thanks, Dan
@danbucholtz, we really need improvement on the boot time. Even the ionic-conference-app downloaded from play store takes 9-10 seconds on my Samsung Galaxy S4 Android Version 5.0.1. This is the app I downloaded --- https://play.google.com/store/apps/details?id=io.ionic.conferenceapp
Boot time for my app with few pages is about 7-8 seconds on the same phone.
So I've tried to attach me via Developer-Tools and got a pretty good timeline-result.
I couldn't track from start because attaching, but you see whats happening:

The Compile Script takes about 500ms, the evalute script from 0ms to 5000ms.
If needed @danbucholtz @jgw96 I can send you the saved timeline for this.
How did you manage to profile this? I can't connect to the app until it's fully started.
BTW I don't know if that's a good result for you, but sadly for my client > 5/6 second startup time is unacceptable.
@Kobzol it isn't a good result, page needs 7s ~ aswell. What I did: Open a page, see your attached device list, start the app first time normal, open the "inspector" switch to timeline tab Close the app now, and the inspector, now start the app again, press inspect, press the in the timeline tab ultra fast the record button ;) The first 1-2 seconds when the app is starting I cant attach aswell, but the rest is possible with a bit of speedy fingers.
Update: With Ionic1 I got a startuptime 3-4 seconds which was quite acceptable for me
Are you building with AoT? Those times seem slow.
Thanks, Dan
@danbucholtz, In my case I downloaded ionic-conference-app from the play store, pretty sure it would be AOT compiled, please see my comments here
@savanvadalia,
We pulled it out of the play store because it actually wasn't AoT bundled. Our developer made a mistake before publishing. We'll republish a new version soon.
Can you install the latest version of the ionic CLI and app-scripts?
npm install -g ionic@latest
npm install @ionic/app-scripts@latest
And then run ionic build android --prod --release? This will give you an AoT build with an optimized APK. It should start much faster than 9 seconds even on a slow device.
Thanks, Dan
@Dan on what devices are you testing this? Even with every package updated, I can't get under 6 seconds and from what I've seen here, others are having similar experiences.
Did anyone managed to install the latest app-scripts?
Update problems:
If I try to install the latest app-scripts I get following error: (I installed ionic@latest before)
C:\Users\graphefruit\Documents\o3>npm install @ionic/app-scripts@latest
ionic-hello-world@ C:\Users\graphefruit\Documents\o3
`-- @ionic/[email protected] invalid
+-- [email protected]
+-- [email protected]
`-- [email protected]
+-- [email protected]
`-- [email protected]
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\ch
okidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@
1.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"
})
After this I started a complete new project, ionic start o4 --v2 with the same error.
Maybe I don't get the update mechanismen - do I need to grab myself into the package.json, or need to delete the node_modules folder?
I tried to update manually set app-scripts, and run npm install, but it crashed.
Neither the package.json was updated automatic to 0.47
So I build the project now with 0.0.45 and --prod --release
And the startup time was 7-8s aswell.
@danbucholtz I think I have always been using AOT until now as I remember I saw ngfactory files somewhere. I am still bit resistive at present to move to newer app-script version as my current version 0.0.46 was doing a decent job for me. But anyways I will take your word and update to 0.0.47 and let you know what happens.
Savan
@danbucholtz I updated to latest ionic-app-scripts and started receiving this error (See below screenshot). Also I have strictly followed the upgrade procedure mentioned in the release notes.
Could you please help with this?

Thanks Savan
@graphefruit I didn't had any issues with installing latest ionic-cli and installing npm packages at project level. I hope you are following the release procedure here. But, as I mentioned above I am getting a different run-time error "Unexpected value 'undefined' declared by the module 'AppModule'".
Also running 0.0.45 with --prod --release won't help. Dan asked to run that with version 0.0.47 as from 0.0.47 and on wards this will be the way to generate a production build. With prior ionic-app-script versions ionic run android generated the production build by default.
@savanvadalia Thanks for your feedback, in the procedure theres not much written.
I also started a fresh project, and did npm install -g ionic@latest before.
So you just runned both commands in your project folder? Or did you do any specific?
Like I said, I already tried to remove the node_modules folder aswell, and did npm-install afterwards.
But in my opinion, it won't help when the package.json isn't updated to the latest app-scripts version. 0.47 but when I do this manually it crashes even more...
Normaly they post in the changelog the newest package.json and what to update.
Update, finally managed it to resolve it with these commands:
npm install ionic-angular@nightly --save
npm install @ionic/app-scripts@latest --save-dev
Let the build begin.
Build test
So, build went through, funny fact - I needed to "strg +c" because ngc-started was shown for more then 10 minutes, after this, the build was continued, the second time it run without any problems.
Size: 9.2 MB
The main.js.map is still existing when building for production
Starting the app needs 7-10 seconds (depends on device) so it looks like it went more worse then before. (Note 1, Note2)
On a Google Pixel XL the startup time was about 4.5 to 5 seconds Compared to my old app-version its still 1-2 seconds slower (3.5 seconds startup time)
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3-201612142137
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 8.1
Node Version: v6.9.1
Xcode version: Not installed
Update 2:
I've just compared the sizes from the old build with 0.45 and with 0.47 - the main.js has (nearly ~10kb) the same size - 3MB. - Don't know if this should be affected aswell.
Update3:
Thats the best snapshot after 15 minutes try for the loading:
