Angular Universal: real app problems
Angular Universal is an open-source project that extends the functionality of @angular/platform-server
. The project makes server-side rendering possible in Angular.
Angular Universal supports multiple backends:
Another package Socket Engine is a framework-agnostic that theoretically allows any backend to be connected to an SSR-server.
This article will discuss the issues and possible solutions we encountered while developing a real application with Angular Universal and Express.
How Angular Universal Works
For rendering on the server, Angular uses the DOM implementation for node.js — domino. For each GET request, domino
creates a similar Browser Document object. In that object context, Angular initializes the application.
The app makes requests to the backend, performs various asynchronous tasks, and applies any change detection from components to the DOM while still running inside node.js environment. The render engine then serializes DOM into a string and serves up the string to the server. The server sends this HTML as a response to the GET request. Angular application on the server is destroyed after rendering.