The dicision boundary between Angular & Angular Universal

浪子不回头ぞ 提交于 2019-12-24 13:26:18

问题


I am working with Angular 6.1.0. The problem I am trying out the demo on Server Side Rendering via the official doc here.

They say, it's angular Universal meaning:

A normal Angular application executes in the browser, rendering pages in the DOM in response to user actions. Angular Universal generates static application pages on the server through a process called server-side rendering (SSR). You can easily prepare an app for server-side rendering using the Angular CLI.

Now I have an angular application that has a bunch of screens and some kinda UI flow with user interaction. More of a PWA (Progressive Web App) than a website.

The application contains user log-ins that are completely static and is the landing view. The application contains dynamic views as well like views with charts and views that need calling APIs to fetch data.

The problem I am facing is that even after gzip, --prod & almost all things from a bunch of websites, the time it takes to load the first view (log-in) is around 30-60 seconds.

My questions are:

  1. Is it advisable to use SSR, to make the static User Log in page Server Rendered for the application to load quickly?
  2. If Yes, Do I need to port my whole Angular Application to Angular Universal? If Yes, is there any link that I can follow?

回答1:


Server side rendering is often helpful for speeding time to initial render. Generally you shouldn't have to change much to add SSR to an angular application, but any direct access of browser apis / dom will need refactoring to abstractions provided by angular. For example you may need to use Renderer2 object (eg: https://alligator.io/angular/using-renderer2/)

The process for adding SSR is documented pretty well at the link you provided to the official docs, and there are a variety of blog posts around it too - just beware of outdated information.

One thing to bear in mind is that unless you use cookie based authentication you won't be able pre-render pages that require a user to be logged in (as you won't have their session information on the server side)

Another option you could look at for improving the startup time of your application is lazy loading of features / routes. You can more information about this here: https://angular.io/guide/lazy-loading-ngmodules



来源:https://stackoverflow.com/questions/53972946/the-dicision-boundary-between-angular-angular-universal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!