lazy-loading – Stepan Suvorov Blog https://stepansuvorov.com/blog Release 2.0 Sun, 09 Jul 2017 20:36:04 +0000 en-US hourly 1 https://wordpress.org/?v=6.3.1 ng-nl 2017. brief review https://stepansuvorov.com/blog/2017/03/ng-nl-2017-brief-review/ https://stepansuvorov.com/blog/2017/03/ng-nl-2017-brief-review/#comments Thu, 16 Mar 2017 23:32:05 +0000 http://stepansuvorov.com/blog/?p=3299 Continue reading ]]>

Already like a good tradition I visited ng-nl conference (ng-nl 2015, ng-nl 2016).

Same as previous year it was great place and awesome people around.

But this time they really messed up with the schedule. I expected to have order of the topics that is provided on official web site, but appeared that it’s not actual and I had to follow the app one, basically the only place. And the app was lagging :(

Strange that this year I did not see anybody from the core Angular team. Also no old good Pascal Precht and Tero Parviainen in the list. At least we had good presentation by Todd Motto about Reactive Forms and really inspiring GraphQL talk by Uri Goldshtein.

…Instead of a keynote it was a talk…

Angular’s Reactive Forms by Todd Motto (code, video)

It was the same talk that Todd gave on ng-be. (see ng-be 2016 brief review). But today he was in a hurry to present all the materials and did not really keep the focus of audience. It might be some difficulties with understanding for developers who did not try Angular Forms before.

Good part comparing to ng-be talk was general architectural overview and going deep into real code from the high level.

some Q&A:

  • automatic generation HTML(not to duplicate form-model description twice)
    • no solution for now
  • good example of structural directive and dynamic component
    • structural directive – reimplementation of ngFor is pretty nice one
    • dynamic component – wizard or toster concepts
  • opinion about Augury
    • did not have time for it. Working hard on the course.

Demystifying Ahead-Of-Time compilation in Angular by Wassim Cheghamslides, video)

Quick intro about JIT.

JIT bad points

  • bundle size
  • perfomance
  • bootstrapping
  • security

AOT generates VM friendly code, but needs context, and context is provided by ngModules.

some words about Tree Shaking (30-60% less code)

So good points about AOT:

  • no security eval issue
  • faster time to interaction
  • smaller vendor bundle size

Easy use with angular-cli:

ng build --aot

Problems to make code “AOT ready”

  • lambda expression (must be export )
  • access modifiers (template properties should be public)
  • no variable exports

Q&A:

  • security: looking for interesting compiler injection examples
    • don’t know any, but evals are always evil.
  • bundle size: AOT makes only vendor part smaller, but your app code became bigger
    • yes, that was mentioned with asterisk on the slides
  • angular universal: what’s the status?
    • now SSR is part of ng4, but Angular Universal still exists like something bigger. We are working on different server rendering engines right now. Current implementation is on express. We would love to get as much feedback as possible from real projects.

Building a dynamic SPA with Angular by Filip Bech-Larsen (slides, video)

It was creasy talk about wrong way of doing things in Angular and reinventing own wheel.

So general, about everything…

about aot, about ssr…

need to review the video and return back to you with more details. for now have unstructured mess in my mind.

Addicted to AngularJS by Pete Bacon Darwin and George Kalpakas (video)

What’s wrong with AngularJs?

  • scaling to large teams
  • scaling to large applications
  • different platforms are not supported

Why not just go Angular right away

  • apps are really large
  • a lot of 3rd party dependancies
  • code base is large (other projects also on AngularJs as well)

ngUpgrade, steps to go:

  • correct structure with typescript
  • bootstrapping
  • downgrading components (so you create new components in Angular style but downgrade to AngularJs to make it work all together inside one app )
  • downgrading services
  • upgrade components (it works with AOT!!!)
  • upgrade services
  • rewrite all to Angular

Future

  • lazy loading
  • better testing story
  • better dual-router story
  • less boilerplate (better compiler integration + tooling)
  • better docs and examples

Q&A with George:

  • Is ngUpgrade for upgrading old components fixes templates as well?
    • Yes
  • Seriously?!
    • Yes.
  • So we will be able to run AOT for old components?!
    • Yes!

ACME (Angular CLI to Manage Everything) by David Müllerchen (code, video)

Funny Lego story about about Angular CLI and back to command line running all the commands one by one:

npm i -g @angular/cil
ng new ng-nl-demo --routing
cd ng-nl-demo
ng serve

Also code generation

ng g component hi-nl
ng g module foo

…and runinng on diffrent environments.

Could be handy for newbies, but for people who already tried angular-cli quite a boring talk.

Q&A:

  • Do you know about any plans to have 3rd party module installation via angular-cli (like ng install angular-material)
    • Don’t know.
  • Same about libraries. It would be really convenient to see environment ready for library creation.
    • Don’t know.

Component based API for your Angular Components with GraphQL by Uri Goldshtein (videos)

Why not REST:

  • lots of calls
  • lots of nested unneeded data

Key points:

  • it’s only single request, and no useless overfetching.
  • Schema to describe data/request structure.
  • nice tool to check our graphQL requests
  • some documentation on Angular Cookbook.
  • Apollo Client chrome extension.
  • easy to use with angular. (Example are coming…)
  • the way to synchronise the state
  • Any backend – Any client – Any language.

Improving Startup Performance with Lazy Loading in Angular by Manfred Steyer ( code , video )

I’ve already saw this talk on ng-be, so I decided to go to workshop instead.

Strictly recommend you to watch part about preloading of lazy modules.

 

Workshop: Maxim Salnikov – Progressive Web  Apps using the Angular Mobile Toolkit

It was just a disaster for audience and for Maxim. He prepared such a great workshop, but to do it in a proper way we would need 4-6 hours, but had to manage to finish in about 30 minutes.

You can check here detailed step-by-step description of the workshop.

 

Breaking Bias by Joy Eamesvideo )

Nothing todo with Angular, just talk about psychology and our stereotypes/biases

  • difference between tables

these 2 tetragons have the same sides!

 

 

]]>
https://stepansuvorov.com/blog/2017/03/ng-nl-2017-brief-review/feed/ 1
Angular: Lazy Loading and Preloading strategy https://stepansuvorov.com/blog/2017/03/angular-lazy-loading-and-preloading-strategy/ https://stepansuvorov.com/blog/2017/03/angular-lazy-loading-and-preloading-strategy/#comments Sun, 05 Mar 2017 10:53:59 +0000 http://stepansuvorov.com/blog/?p=3286 Continue reading ]]> Almost all of you know that it’s possible in Angular to load modules asynchronously by using Lazy Loading Router feature, you just need to specify special parameter for the state – loadChildren:

[javascript]
{ path: ‘lazy’, loadChildren: ‘./lazy/lazy.module#LazyModule’ }
[/javascript]

and setup child module with RouterModule.forChild method:

[javascript]
const routes: Routes = [
{ path: ”, component: AdminComponent }
];

@NgModule({
imports: [
CommonModule,
RouterModule.forChild(routes)
],
declarations: [AdminComponent]
})
export class LazyModule { }
[/javascript]

In most cases you are doing so not to load all the modules at once make “first screen” appearing quicker. But it’s not all folks, you also could preload all your lazy modules when your application base is loaded so: you are showing first screen fast and after load other modules in background to show them immediately when it’s needed. And it’s really usy to setup: for you main RouterModule you add the property preloadingStrategy:

[javascript]
imports: [
CommonModule,
RouterModule.forRoot(appRoutes, { preloadingStrategy: PreloadAllModules }),

],

[/javascript]

But even more interesting that you could create your own strategy for loading logic. For example you want to start loading the rest of the modules in 5s after app is loaded:

[javascript]
export class CustomPreloadingStrategy implements PreloadingStrategy {
preload(route: Route, fn: () => Observable<boolean>): Observable<boolean> {
return Observable.of(true).delay(5000).flatMap( (_: boolean)=> fn());
}
}
[/javascript]

and you can also specify which routes should not be preloaded:

[javascript]
export class CustomPreloadingStrategy implements PreloadingStrategy {

public preload(route: Route, fn: () => Observable<boolean>): Observable<boolean> {
if (route.data && route.data[‘nopreload’]) {
return Observable.of(false);
}

return Observable.of(true).delay(5000).flatMap((_: boolean) => fn());
}
}
[/javascript]

]]>
https://stepansuvorov.com/blog/2017/03/angular-lazy-loading-and-preloading-strategy/feed/ 3