0

I've developed an web application with Angular, Springboot and Jhipster. I want to know if it's possible to optimize the loading of the application. if yes how can I do that.

Here is the results I get

Here is navbar and home components (loaded first).

navbar.component.ts

    import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { JhiLanguageService } from 'ng-jhipster';

import { ProfileService } from '../profiles/profile.service';
import { JhiLanguageHelper, Principal, LoginModalService, LoginService } from '../../shared';

import { VERSION, DEBUG_INFO_ENABLED } from '../../app.constants';

@Component({
    selector: 'jhi-navbar',
    templateUrl: './navbar.component.html',
    styleUrls: [
        'navbar.css'
    ]
})
export class NavbarComponent implements OnInit {

    inProduction: boolean;
    isNavbarCollapsed: boolean;
    languages: any[];
    swaggerEnabled: boolean;
    modalRef: NgbModalRef;
    version: string;

    constructor(
        private loginService: LoginService,
        private languageHelper: JhiLanguageHelper,
        private languageService: JhiLanguageService,
        private principal: Principal,
        private loginModalService: LoginModalService,
        private profileService: ProfileService,
        private router: Router
    ) {
        this.version = VERSION ? 'v' + VERSION : '';
        this.isNavbarCollapsed = true;
        this.languageService.addLocation('home');
    }

    ngOnInit() {
        this.languageHelper.getAll().then((languages) => {
            this.languages = languages;
        });

        this.profileService.getProfileInfo().subscribe((profileInfo) => {
            this.inProduction = profileInfo.inProduction;
            this.swaggerEnabled = profileInfo.swaggerEnabled;
        });
    }

    changeLanguage(languageKey: string) {
      this.languageService.changeLanguage(languageKey);
    }

    collapseNavbar() {
        this.isNavbarCollapsed = true;
    }

    isAuthenticated() {
        return this.principal.isAuthenticated();
    }

    login() {
        this.modalRef = this.loginModalService.open();
    }

    logout() {
        this.collapseNavbar();
        this.loginService.logout();
        this.router.navigate(['']);
    }

    toggleNavbar() {
        this.isNavbarCollapsed = !this.isNavbarCollapsed;
    }

    getImageUrl() {
        return this.isAuthenticated() ? this.principal.getImageUrl() : null;
    }
}

home.component.ts

import { Component, OnInit } from '@angular/core';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { EventManager } from 'ng-jhipster';

import { Account, LoginModalService, Principal } from '../shared';

@Component({
    selector: 'jhi-home',
    templateUrl: './home.component.html',
    styleUrls: [ 'home.css' ]
})
export class HomeComponent implements OnInit {
    account: Account;
    modalRef: NgbModalRef;

    constructor(
        private principal: Principal,
        private loginModalService: LoginModalService,
        private eventManager: EventManager
    ) {}

    ngOnInit() {
        /*  this.principal.identity().then((account) => {
            this.account = account;
        }); */
        this.registerAuthenticationSuccess();
    }

    registerAuthenticationSuccess() {
        this.eventManager.subscribe('authenticationSuccess', (message) => {
            this.principal.identity().then((account) => {
                this.account = account;
            });
        });
    }

    isAuthenticated() {
        return this.principal.isAuthenticated();
    }

    login() {
        this.modalRef = this.loginModalService.open();
    }
}

home.component.html

<div class="row">
    <div class="col-md-3">
        <!-- <span class="hipster img-fluid img-rounded"></span> -->
    </div>
    <div class="col-md-9">
        <h1 class="display-4">Bienvenue!</h1> 
    </div>
</div>
didate
  • 11
  • 1
  • 1
    Yes, it is possible – Marged Jan 31 '20 at 21:39
  • 1
    We can't give specific answer without seeing your project structure and/or your code along with other pertinent information like how much data you're loading on screen when the app initializes, etc. In general, you optimize load times by lazy loading feature modules and/or using resolvers. When you build for production with the `--prod` flag, tree-shaking ensures that unused modules are not included in the dist folder. If you don't have to worry about IE support, ensuring that your target ES standard is set to es2015 in your tsconfig.json will result in a smaller bundle size. – Kyler Johnson Jan 31 '20 at 21:43
  • thank you @KylerJohnson, I updated the question to add some code. I'm going to try your suggestions – didate Jan 31 '20 at 22:02
  • see this entry: https://stackoverflow.com/q/59987797/7773582. In Spring as well as in Angular there are various ways to lazy load fields, classes, types respectively components. JHipster will - at the moment - not care about it, you have to implement it as you like after generation. – Jochen Haßfurter Feb 01 '20 at 11:38

0 Answers0