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

LAZY LOADING in IONIC2

Open mohammedzamakhan opened this issue 10 years ago • 43 comments

Short description of the problem:

Angular Router (Angular 2) has the ability to lazy load components, since Ionic is using its own router, will we have the functionality to lazy load the components?

What behavior are you expecting?

Lazy Loading Components

mohammedzamakhan avatar Sep 16 '16 18:09 mohammedzamakhan

@CompitDanielos ... Thanks very much for replying! The reason I'm asking, it too get it working, but ion-content gets hidden behind the ion-header - what did you do to avoid this?.... Thanks so much for your help! (I've been searching for a solution for a few days now)

Dutchboy avatar Jan 11 '17 09:01 Dutchboy

So I changed my whole ionic project and now I have built an angular 2 app with the router to be able to loadchildren. I changed BrowserModule to CommonModule. When trying to present something (modal, actionsheet, alert) I get TypeError: Cannot read property _getPortal of undefined. So I looked in to Ionics code and there is an error here: var portal = this._appRoot._getPortal(appPortal); Anyone has idea how to fix this? I guess the approot isn't declared since i don't use ion-nav.

emmawi avatar Jan 17 '17 11:01 emmawi

@emmawi That problem I had / have too... My humble opinion is that the Nav / NavController is made way toooo important by Ionic, which will ultimately make the whole Ionic framework unworkable... Ionic is just a presentation-layer - a (near) perfect one, I'm not judging, but not more. I frustrated myself with this, trying to dig into someone else's source code (which is massive, and again, no opinion nor judgement!) losing a week or more, I came across other approaches.

Also, the whole hybrid approach makes me more and more skeptical. Especially when I can't split my code into several "modules". When a user decides to leave the app, simply taking a phone call or answers some whatsapp messages and later on wants to come back to my app, he/she for sure will find out the whole application has been removed from memory by the OS (android/ios), simply because I couldn't make it small? Because I cannot develop it into several separate modules - with one module small enough to be allowed alive by the OS, which keeps important data and notifications in-memory.

Think lazy loading. The whole presentation layer doesn't have to in memory when running in the background (taking for granted the root module, which is (can be) just an empty placeholder.

Back to my growing fear with regards to Hybrid. Even though I have had some mixed experience with Telerik, the founders of Nativescript, I was (and still am) surprised to see someone I value a lot, Nathan Walker @NathanWalker , providing a working seed...

Hmmmm... I now realize I wrote this monologue in the Ionic section... I also realize nobody asked for it really... But, on the other hand, if someone told me about his endeavors before, it would have saved me a lot of time. @NathanWalker provides a huge amount of links to others explaining loads of stuff. Go there and ultimately, you might agree with me.

Dutchboy avatar Jan 17 '17 13:01 Dutchboy

@emmawi @Dutchboy I was struggling a lot as you guys, so I decided to use another framework. I moved to Onsen UI which shows better performances on both iOS and Android. Also, I managed to make it working with lazy loading. It's a bit tricky, but still works perfectly. The example is here.

ivaylopivanov avatar Jan 17 '17 14:01 ivaylopivanov

@emmawi @Dutchboy @ivaylopivanov Hey guys, note the lazy load branch. https://github.com/driftyco/ionic/tree/lazy-load . It looks like our concerns on pwa are being noticed and worked on. RC5 was also a step in the right direction on angular-universal as well. It looks like the Ionic team is working towards what we want.

alexthebuilder avatar Jan 17 '17 14:01 alexthebuilder

That is good news. I was actually in the thoughts of ditching ionic all together because of this. The most important thing in my app is being able to lazy load modules.

@jgw96 @danbucholtz Is there going to be a feature in the ionic framework to lazy load children like in angulars router? And if so, do you have a timeframe on it?

emmawi avatar Jan 17 '17 14:01 emmawi

@emmawi @alexthebuilder with what I've done today I'm thinking of ditching Ionic. Look at here This is a fork / cooperation of here - Mico Gechev is a long-time active guy who used to be responisble for the Guidelines of AngularJS (1) .... He knows what he's doing.... But step right to the advanced seed (first link)....

Using this seed, you can then mix it with @ivaylopivanov work to get the web interface up.... or just use the Material2 of Angular....

Because - from what I've learned, you should not skip angular-router.... It is perfect, it comes directly from the ngrx team and these guys are beyond perfect.

Dutchboy avatar Jan 17 '17 16:01 Dutchboy

@emmawi I see you've tried to reach some guys - don't worry, they will not respond how you hope them to. Please realize that Ionic has tried to build a Nav/NavController system with a team which is not comparable to the team of Angular2. And they should never have done this - crossing the line outside the presentation layer....

Dutchboy avatar Jan 17 '17 16:01 Dutchboy

This feature is coming to Ionic shortly. Probably post 2.0. We have a working prototype. With that in mind, we are going to close this issue and focus on the implementation.

Thanks, Dan

danbucholtz avatar Jan 18 '17 17:01 danbucholtz

This issue has been open more than 6 months. Even before it, several people hoped it would have been solved when Angular team adopted wisely the ngrx/router ... The problem is that the NavController is a pain... Another problem is that the Ionic Team doesn't listen... An answer I read a lot - it will be implemented and so now we're closing it.. "Post-V2" meaning V3? Or "in due time"? V4? September? 2018?

Dutchboy avatar Jan 18 '17 18:01 Dutchboy

via driftyco/ionic-app-scripts/issues/623

We will have to more to share on this soon. Tracking the topic here. driftyco/ionic-app-scripts#693 Thanks, Dan

let's see whether this may bring lazy loading support for components...

mikezks avatar Jan 31 '17 00:01 mikezks

Our team is waiting for that solution as well .. with all the optimizations we achieved only 1.7MB of minified JS which takes 3.2sec (on desktop) to evaluate after loading and only code-splitting could help there.

bobrosoft avatar Jan 31 '17 10:01 bobrosoft

@rodelima It is so simple to just copy-paste a link to a completely different subject... It both shows disrespect for all the people here which actually took the effort to explain and it also shows you really don't have a clue of what we're discussing here.

Pictures / Images being "lazy loaded" - this has nothing to do with program code being lazy loaded and being run afterwards...

The discussion here is the choice of the Ionic Team to develop their own mechanism, NavController. They did this in May '16. Or before.

Simply, because they didn't want to wait for the solution being cooked by the humongous team of Angular2.

The question should be - Why Did The NG2 Team Wait So Long.

Because they wanted a superior mechanism? Because they learned from their previous mistake (resulting in an external angularUIrouter)?

In May '16, some members of the NG2 Team got separated from the core team and did a wonderful job bringing Redux into the NG2 Space. This is called NGRX. And guess what happened.... The NGRX-Router got promoted, got removed from the NGRX repository, and got renamed NG2 Router.

With NG2 still in RC - these things happen quickly.

Meanwhile, the Ionic Team thickheadedly held on to their "implementation" of NavController. Tried to patch it etc...

But with that, one huge mistake and misinterpretation is unveiled.

Even though Ionic is a good effort - it still is "just" a User Interface Layer

And with brute-forcing us, the developers, to use a faulty NavController, we, the developers, will never be able to fully accomplish our targets - to successfully finalize a working Application.

We are forced to tell our users "hey, you, listen, wait for 10 seconds until your application is started" "hey, you, don't complain" ..... Every time the user brings back our application.... ..... After reading a Whatsapp message, bangggg 10 seconds.... (because some Android phones have strict memory garbage collection mechanisms in place)

While, at the same time, NG2 with code-split allows to keep just a tiny block in-memory so that even the most rigorous GC mechanisms allow these tiny codes in-memory.

THIS Lazy Loading we are discussing here.....! And not just some silly image async refresh, which erratically was called "lazy loading" too by the Ionic Team....

My advise is:- Get Rid Of NavController!!!!! Not tomorrow, not in a month, not "next version" - BUT YESTERDAY

Dutchboy avatar Jan 31 '17 14:01 Dutchboy

@Dutchboy OK. Sorry. My mistake. I got it wrong. Thank you for the explanation

rodelima avatar Jan 31 '17 14:01 rodelima

@rodelima no problem - really. 😄 don't take this too serious. we are all awaiting this feature, but @Dutchboy seems to be a little bit too frustrated IMO.

mikezks avatar Jan 31 '17 18:01 mikezks

@mikezks It is actually hard to get me frustrated. But... ... If an issue is obviously An Issue for more than a few months. ... When that same issue has been tackled by the original framework itself (NG2 Team and their kings at NGRX) ... And I then see a cooperative trace of messages (read all the above) without annnnny Ionic Team member picking it up

And then being utterly surprised to see this issue closed by @danbucholtz - who, until then hasn't shared one helping suggestion, and just closes it with "Don't worry, soon"...

Well, @mikezks :-) yes, I sometimes lose myself and start typing the whole history of such issue...

  • Ionic being a UX layer framework (until V1 at least, by far the best in its own right)
  • Ionic overplaying itself by forcing developers to abandon NG2 Router, which, does allow AoT and LL
  • Ionic not listening to (mostly) free customers, developers... Mind you, people start abandon it as we speak (uhhh - write :-) ) See the statistics - see the growth of Nativescript

Ionic should abandon NavController yesterday.

Dutchboy avatar Jan 31 '17 20:01 Dutchboy

@Dutchboy i agree with you in most of the points, nevertheless the tone is to harsh IMO. ionic is still OSS we all benefit of and i am sure ionic team does their best to provide a good framework.

but i understand your frustration, because i have a similar issue with Microsoft Azure Functions were no progress happens and no schedule is known.

also closing this issue w/o a solution is kind of odd. i would need Lazy Loading and Angular Universal support urgently as well, but it seems we have to wait a little bit longer, but i hope 2.1 or 2.2 will include these features.

until that, all the best & keep the faith. 😉

mikezks avatar Jan 31 '17 20:01 mikezks

I agree with @Dutchboy, I think ionic 2 should be a UX layer as well, by creating components and behaviors that is focused (but not only) to mobile (touch, gestures, etc). But this (UX) should be created using the same ecosystem as angular2 (even the router). This benefits both communities (ionic and angular), instead of splitting by using a different router (navcontroller). Anyway, if ionic2 keep the navcontroller, it should be allowed (even if not recommended) to use the angular2 router (even if some features not work). This could allow the ionic2 to be a starter project for web only projects (with mobile friendly features).

I've been working on this myself https://github.com/jvitor83/angular-ionic-seed but am suffering the same issue that was quoted here

jvitor83 avatar Jan 31 '17 21:01 jvitor83

Sorry I just wanted to chime in. We are actively working on this. Your concerns about bundle size and lazy loading routes are the same concerns that we have been discussing internally. There currently is no simple solution.

Your frustrations are understood.

I know that you might have heard this before but I can tell you that this is our top priority.

jthoms1 avatar Jan 31 '17 22:01 jthoms1

@jthoms1, great thx for this update!

mikezks avatar Jan 31 '17 22:01 mikezks