Using Ionic 3 lazy loading can cause delays when loading large HTML files

My current project involves using Ionic 3, and I'm facing some challenges with lazy loading.

The ResultPage, which has a template named resultpage.html, contains over 1000 lines of HTML code. In the HomePage, my intention is to navigate to the ResultPage by using navCtrl.setRoot. However, upon calling this function, the screen freezes for approximately 3-4 seconds before redirecting me to the ResultPage. This delay results in a poor user experience. The issue only occurs with large templates, specifically the first time I access that page. To address this problem, I removed lazy loading from the ResultPage, and the lag disappeared. I am uncertain if this is the correct approach. Could someone provide guidance on what steps I should take in this situation?

Thank you very much!

Answer №1

To conceal this information from the user, consider employing lazy loading in your application while also implementing preloading eagerly for specific pages. For more details, refer to the documentation.

By default, preloading is disabled, so adjusting this property will have no effect. Eagerly preloading all deep links upon app launch rather than on demand enhances performance. To enable preloading, set preloadModules to true in the main application module configuration:

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp, {
      preloadModules: true // <- Enable here!
    })
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp
  ]
})
export class AppModule { }

If preloading is enabled, modules are loaded based on their priority setting. Priorities can be "high", "low", or "off". Modules without a specified priority default to "low".

Modules with "high" priority load first, followed by those with "low" or no priority.

You can set priority simply by including it in the @IonicPage decorator:

@IonicPage({
  name: 'my-page',
  priority: 'high'
})

In your scenario, consider setting high priority for:

  • The initial screens users interact with when launching the app (e.g., HomePage)

  • The ResultPage to ensure faster loading when users navigate to it.

Note: Preloading pages eagerly could impact app startup time, so preload only essential pages to minimize any delay.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Button for liking and disliking with Angular, Node.js, and

On my Twitter-esque website, I am developing YouTube-style (like-dislike) buttons. However, when it comes to implementing these like-dislike buttons using Angular, Node.js, and MYSQL with NgFor loop and ngIf conditions, I encountered a problem. My database ...

Transform commitment into observable Keycloak

I'm struggling with the keycloak methods and find it overwhelming to redo them. I also have some confusion on how it works. export class AuthGuard extends KeycloakAuthGuard { constructor( protected readonly router: Router, protected readonly ...

Is there a way to customize the size of the image using dangerouslySetInnerHTML in React?

While utilizing dangerouslySetInnerHTML to display article HTML in a React component, I encountered an issue where an image from the HTML content exceeded the page width. Is there a way to resize the image within dangerouslySetInnerHTML? Or can the maxim ...

Error: Reference to an undeclared variable cannot be accessed. TypeScript, Cordova, iOS platforms

Can anyone offer some advice on what might be the issue? I'm encountering an error while building my Ionic app on the IOS platform, but everything is running smoothly on Android. ReferenceError: Cannot access uninitialized variable. service.ts:31 O ...

Self-referencing type alias creates a circular reference

What causes the discrepancy between these two examples? type Foo = { x: Foo } and this: type Bar<A> = { x: A } type Foo = Bar<Foo> // ^^^ Type alias 'Foo' circularly references itself Aren't they supposed to have the same o ...

Combine JavaScript code with its corresponding TypeScript definition located in separate files

I am trying to utilize a specific file from a repository without the need to install its NPM package. This particular file was written in JavaScript and has a separate definition file. The JavaScript file contains an export for the Headers class. The Type ...

What could be the reason why my Angular component is experiencing input issues?

I am facing an issue with my angular class: @Component({ selector: 'main-title', styleUrls: ['main_title.scss'], template: ` <ng-template> <div class="main-title"> <h2 [ngClass]="{&apo ...

Discovering the best approach to utilizing Font Awesome 6 with React

Required Packages "@fortawesome/fontawesome-svg-core": "^6.1.1", "@fortawesome/free-solid-svg-icons": "^6.1.1", "@fortawesome/react-fontawesome": "^0.1.18", "next": " ...

Creating an overloaded callable interface using TypeScript

The thread on implementing a callable interface provides some helpful information, but it doesn't fully address my specific query. interface lol { (a: number): (b: number) => string // (a: string): (b: string) => string // overloaded wi ...

What steps should I take to manage an error image that is not found in a directory on my computer?

I am currently working with a list that displays various information, along with an image search function in an img tag that looks for a specific image related to the information. However, some of the information does not have a corresponding image and I w ...

Collaborate on input field values across different Angular components

I'm currently exploring Angular 8 and facing an issue with two forms in separate components that share some input values. These values update whenever the user leaves the input field. The first component contains these input fields: <input matInp ...

Having trouble with "npm install" stuck at "normalizing tree: http request GET https://registry.npmjs.o"?

After spending several hours attempting to install angular cli, I am encountering issues with the npm package not working properly. I have tried disabling Firewall and even changing the path variable as suggested in some posts, but nothing seems to solve t ...

How to add icons to HTML select options using Angular

Looking for a way to enhance my component that displays a list of accounts with not only the account number, but also the currency represented by an icon or image of a country flag. Here is my current component setup: <select name="drpAccounts" class= ...

Observables waiting inside one another

I've encountered an issue where I need to return an observable and at times, within that observable, I require a value from another observable. To simplify my problem, let's consider the following code snippet: public dummyStream(): Observabl ...

Creating a unique syntax for custom ngIf directives in Angular

Currently, I am in the process of developing a personalized *ngIf directive that will swap out content with a placeholder during loading. After referencing the *ngIf directive (https://github.com/angular/angular/blob/master/packages/common/src/directives/n ...

Troubleshooting CORS Problem in Angular 8 and Java Spring Framework

I've been struggling with a major issue for hours now. I am developing an Angular app that communicates with a Java Spring API. All of my POST/GET/DELETE requests are working fine, except for one: the POST request to "/login", which requires sending d ...

What is the process for incorporating polyfills into Global declarations in typescript when working with modules?

After discovering a polyfill for Array#includes on Stack Overflow and integrating it into TypeScript, I encountered an issue where adding a small import to my file caused it to be transformed into a module. This prevented me from modifying the global names ...

Tips for correctly passing the type of combineReducers: I encountered an error saying "Property '...' does not exist on type 'Reducer<CombinedState{}>"

I am currently integrating TypeScript into my react/redux project. Unfortunately, I am encountering an error that is preventing my app from loading. The issue is shown in the screenshot below: https://i.sstatic.net/HkPwo.png Within my index.tsx file, I a ...

ngIf not working properly with the updated value of [(ngModel)]

I am encountering an issue with a select element that has options. The select is using the [(ngModel)] directive to save selected values into "rightFieldTypeId." I have elements that should be displayed based on the value of "rightFieldTypeId." Even though ...

Clone the git repository to install the @types/... package

Is it possible to install @types/sanctuary using the command yarn install @types/sanctuary? I am interested in installing @types/sanctuary from a specific forked repository: https://github.com/vicrac/DefinitelyTyped/blob/master/types/sanctuary/index.d.ts ...