# Am I stupid or is IONIC 3 lazy loading stupid

**URL:** <https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717>\
**Category:** ionic-v3\
**Created:** [November 1, 2017, 6:34pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717 "2017-11-01T18:34:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![imadbakir](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@imadbakir](https://forum.ionicframework.com/u/imadbakir)\
**Post date:** [November 1, 2017, 6:34pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/1 "2017-11-01T18:34:03Z")

</div>

Hi everyone,  
I have developed few Apps using IONC 1, and I liked it, after the move to Ionic 2 I was a little bit afraid of the transaction and decided to keep using ionic 1 and just wait,  
for a while now, after IONIC 3 was out, I had a deep look into it and I seemed to like it especially after reading about lazy loading Pages and components (the concept), and I’m developing my first IONIC 3 app lazy loading my pages,  
the thing is, Do I really need to create a module for every page and import every Lib/Module I need to use again and again and again for each page?  
do I really need to use different navigation for each module separately in order to be able to lazy load it or am I doing it wrong?  
if the asnwer is Yes, Why?  
if the answer is No, then How?  
what are the standards?

---

<div class="post-metadata">

**Author:** ![SigmundFroyd](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sigmundfroyd/32/111604_2.png) [@SigmundFroyd](https://forum.ionicframework.com/u/SigmundFroyd)\
**Post date:** [November 1, 2017, 6:36pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/2 "2017-11-01T18:36:19Z")

</div>

Sounds like you’re doing it wrong.

If you have your page controller `.ts` file and an accompanying `.module.ts` file, then all you have to do is on another page do  
`navController.push("name-of-page-class-in-a-string");`.

For example, say you have the `HomePage` class, then you’d do:  
`navController.push("HomePage");`

No need to import the module anywhere.

---

<div class="post-metadata">

**Author:** ![imadbakir](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@imadbakir](https://forum.ionicframework.com/u/imadbakir)\
**Post date:** [November 1, 2017, 6:39pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/3 "2017-11-01T18:39:56Z")

</div>

maybe I explained myself wrong, I know about the nav thing you mentioned, but what I actually meant is,  
while I have a Navigation function on App.component, why would I write another function in page.component to do that, can’t I simply inherit from "parent"  
for example storage, session etc… do I need to import a provider or a module in every page to access those things, or can I in some way keep them in one place and use them everywhere, without re-importing them … am not sure if I’m explaining it correctly still…

---

<div class="post-metadata">

**Author:** ![asamarcos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/asamarcos/32/113280_2.png) [@asamarcos](https://forum.ionicframework.com/u/asamarcos)\
**Post date:** [November 1, 2017, 6:44pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/4 "2017-11-01T18:44:29Z")

</div>

What I actually do is to import all providers in app.module.ts. After that when you create a lazy loaded page, you must import IonicPageModule.forChild(YourPage). This import will provide everything you already declared on app.module.ts.

---

<div class="post-metadata">

**Author:** ![imadbakir](https://avatars.discourse-cdn.com/v4/letter/i/3d9bf3/32.png) [@imadbakir](https://forum.ionicframework.com/u/imadbakir)\
**Post date:** [November 1, 2017, 6:46pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/5 "2017-11-01T18:46:07Z")

</div>

That sounds like what I’m looking for,  
sir can you please provide a code snippet to demonstrate your idea,  
what would the folder/file structure be like in that case, do I still need a page module?

---

<div class="post-metadata">

**Author:** ![asamarcos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/asamarcos/32/113280_2.png) [@asamarcos](https://forum.ionicframework.com/u/asamarcos)\
**Post date:** [November 1, 2017, 8:01pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/6 "2017-11-01T20:01:49Z")

</div>

@imadbakir

Yes, you still need a module per page.

One of my lazy loaded pages module (survey.module.ts)

```auto
@NgModule({
    declarations: [SurveyPage],
    imports: [
        JWBootstrapSwitchModule, // Example of a third party module im using only on this page, so it's loaded only here
        IonicPageModule.forChild(SurveyPage) // Here is where your page will inherit app.module.ts payload
    ],
    exports: [SurveyPage]

})
export class SurveyPageModule {}

```

Any page is set in a separate folder, composed of 4 files.

- survey.ts
- survey.scss
- survey.html
- survey.module.ts

My app.module.ts looks like this:

```auto
@NgModule({
    declarations: [
        MyApp
    ],
    imports: [
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: HttpLoaderFactory,
                deps: [Http]
            }
        }),
        BrowserModule,
        ReactiveFormsModule,
        HttpModule,
        IonicModule.forRoot(MyApp),
        IonicStorageModule.forRoot(),
    ],
    exports: [],
    bootstrap: [IonicApp],
    entryComponents: [MyApp],
    providers: [
        AndroidPermissions,
        DatabaseService,
        DatabaseConnectionService,
        TransactionService,
...
...
...
...
rest
]

```

You can import all providers in another file and import this file here. It’s up to you.

best regards

---

<div class="post-metadata">

**Author:** ![Daskus](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@Daskus](https://forum.ionicframework.com/u/Daskus)\
**Post date:** [November 2, 2017, 1:30pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/7 "2017-11-02T13:30:19Z")

</div>

There is an [issue](https://github.com/ionic-team/ionic/issues/12333) on github about lazyloading multiple pages at once, but they closed it and ignore it even though a lot of people need this feature…

---

<div class="post-metadata">

**Author:** ![ipsjolly](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@ipsjolly](https://forum.ionicframework.com/u/ipsjolly)\
**Post date:** [January 14, 2019, 3:44pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/8 "2019-01-14T15:44:23Z")

</div>

Check here simple steps to convert **[Non Lazy to Lazy Loaded App](https://www.freakyjolly.com/optimize-app-loading-by-implement-lazy-loading-in-ionic-3-existing-new-app/)** It also proves great tip to optimize app Startup time in real Devices

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 10:07pm UTC](https://forum.ionicframework.com/t/am-i-stupid-or-is-ionic-3-lazy-loading-stupid/110717/9 "2021-07-19T22:07:01Z")

</div>

Closed on July 19, 2021, 10:07pm UTC


