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

Hi @jthoms1, will changes get merged with master before beta 11?

TheMohanraj avatar Jul 15 '16 06:07 TheMohanraj

Yea I waiting offline compiling too, but something can be made now. Our site is completely on Ionic2 beta.8 http://m.sherpadesk.com/

I have hybrid app too and I did some optimizations and got 417ms loading time. Look at report https://tools.pingdom.com/#!/DW6Td/http://m.sherpadesk.com/17 Also Site size decreased 600% (3Mb -> 500 Kb) User interaction response speed improved 2000% (2 seconds -> 100ms)

Good recommendations: http://blog.angular-university.io/how-to-run-angular-2-in-production-today/36

I'll post all my gulp settings and link to appstore here: http://www.sherpadesk.com/blog/

evgeniynet avatar Jul 15 '16 12:07 evgeniynet

@Evgeniynet very nice.

Few questions:

  1. When installing app it opens instantly but the. I get loading your profile and it seems to stuck for 5 sec. Why?
  2. How did you optimize loading time without offline compilation?
  3. Is your mobile website is ionic2?
  4. Is your desktop website ionic2?

I'm contemplating on using ionic 2 but the only thing which is stopping me that I need to manage webapp project + mobile ionic2 project.

Thanks

justme1 avatar Jul 15 '16 13:07 justme1

@evgeniynet is it served by node? It seems to be pre-compiled. But most of our case it will be device storage hosting (phonegap application).

TheMohanraj avatar Jul 15 '16 13:07 TheMohanraj

@dheran, no, it is hosted on Azure website, only plain html and js files which produced by ionic 2 gulp build task.

evgeniynet avatar Jul 15 '16 14:07 evgeniynet

@justme1

  1. yea, I did trick with http://www.bennadel.com/blog/3105-creating-a-pre-bootstrap-loading-screen-in-angular-2-rc-1.htm

Is your mobile website is ionic2? yes

Is your desktop website ionic2? yes

My ios app just loads site in webview, nothing more.

only one codebase for iOS, Android and Windows Phone, web app, Chrome extension and even an Apple iWatch

I set special flag to stop loading cordova, to prevent gap:// error

I am writing complete guide on this on http://www.sherpadesk.com/blog/

evgeniynet avatar Jul 15 '16 14:07 evgeniynet

@evgeniynet

  1. It this is the case then it seems not really faster loading :-)

Regarding one codebase:

From what I understood ionic2 isn't supposed to be used as a desktop website as it's fully supported by browsers. Don't you mind this issue?

justme1 avatar Jul 15 '16 14:07 justme1

Count me in on waiting for this feature.

masimplo avatar Jul 19 '16 18:07 masimplo

Hi, any updates on this? I'm using version: Cordova CLI: 6.3.0 Ionic Framework Version: 2.0.0-beta.10 Ionic CLI Version: 2.0.0-beta.35 Ionic App Lib Version: 2.0.0-beta.19 LG Nexus 5 (os 6.0) Sidemenu tutorial app v1 loads in 3 seconds --v2 sidemenu load in 6 seconds

kLkA avatar Aug 05 '16 11:08 kLkA

The ahead-of-time compiling functionality is coming in Beta 12. This will dramatically speed up initial load and significantly reduce the size of the bundle. We're about to launch Beta 11, so this is up next. This is our #1 priority. We have it working on a branch, so we're close.

Thanks, Dan

danbucholtz avatar Aug 05 '16 13:08 danbucholtz

its really slow for the first time. waiting for the optimization

tanzeelrana avatar Aug 05 '16 23:08 tanzeelrana

@danbucholtz or anyone add this issue to beta 12 milestone

TheMohanraj avatar Aug 07 '16 11:08 TheMohanraj

@danbucholtz can we use the branch code? Sorry, can't wait until beta 12 release.. :-( Please give us a quick release..

TheMohanraj avatar Aug 09 '16 08:08 TheMohanraj

@dheran,

This change requires Angular RC 5 which isn't out yet. We will release it as soon as beta 12 is ready to go. We're not going to release until it's ready to go.

A good short term fix could be switching to use inline-templates as shown below. This will be faster short term. Give it a shot and see if it speeds things up for you some.

@Component({
   template: `
   <ion-content>
      <div>content</div>
   </ion-content>
  `
})
export MyClass {
}

Thanks, Dan

danbucholtz avatar Aug 09 '16 15:08 danbucholtz

@danbucholtz Inline actually helps a lot. I wrote a small code in my gulpfile.js which does that during build.

gulp.task('build', ['build:prequel'], function(done) {
  glob('./www/build/**/*.html', function(e,files) {
    var indexPath = './www/build/js/app.bundle.js'
    var js = fs.readFileSync(indexPath, 'utf8');

    async.eachSeries(files, function(file, callback) {
      filename = file.substr(6)
      var html = fs.readFileSync(file, 'utf8');
      js = js.replace("templateUrl: '" + filename + "'", "template: `" + html +"`")
      callback()
    }, function() {
      fs.writeFile(indexPath, js, 'utf8', function(err, data) {
        done()
      });
    })
  })
})

Yeah, this is not clean and is not the best way to do so. But it works like a charm.

prijindal avatar Aug 09 '16 23:08 prijindal

PS: Inlining does not help a lot with initial startup, maybe at most 0.5 seconds. But it sure makes it smoother between page transition or whenever you are dynamically loading a component.

prijindal avatar Aug 09 '16 23:08 prijindal

@prijindal, Nice! That's awesome! With the AoT compiler coming in Beta 12, it won't matter whether the template is inline or external file. It will be converted to pure JS as part of the build process. Nice work figuring that out!

Thanks, Dan

danbucholtz avatar Aug 10 '16 04:08 danbucholtz

Hi, i checked Angular page and i see that RC5 is released. What did you mean by "until rc5 out"?

kLkA avatar Aug 10 '16 06:08 kLkA

@kLkA , @dheran Give Ionic team a break - they sure are trying to get betas out as fast as possible and pinging everyday does not help them in any way. They are working directly with Google on Angular and definitely should know that Angular2 rc5 is out.

trakhimenok avatar Aug 10 '16 08:08 trakhimenok

Yeah and Google released rc 5 like just few hours ago. I am sure they are aware of the release and are working something out to get it into beta 12

prijindal avatar Aug 10 '16 09:08 prijindal