Book Image

Server-Side Enterprise Development with Angular

By : Bram Borggreve
Book Image

Server-Side Enterprise Development with Angular

By: Bram Borggreve

Overview of this book

With the help of Server-Side Enterprise Development with Angular, equip yourself with the skills required to create modern, progressive web applications that load quickly and efficiently. This fast-paced book is a great way to learn how to build an effective UX by using the new features of Angular 7 beta, without wasting efforts in searching for referrals. To start off, you'll install Angular CLI and set up a working environment, followed by learning to distinguish between the container and presentational components. You'll explore advanced concepts such as making requests to a REST API from an Angular application, creating a web server using Node.js and Express, and adding dynamic metadata. You'll also understand how to implement and configure a service worker using Angular PWA and deploy the server-side rendered app to the cloud. By the end of this book, you'll have developed skills to serve your users views that load instantly, while reaping all the SEO benefits of improved page indexing.
Table of Contents (5 chapters)

2. Server-Side Rendering

Activity 9: Implementing the Transfer State Cache

Solution:

  1. Import TransferHttpCacheModule from @nguniversal/common in AppModule:
    import { TransferHttpCacheModule } from '@nguniversal/common';
  2. Next, import ServerTransferStateModule from @angular/platform-server in AppServerModule:
    import { ServerTransferStateModule } from '@angular/platform-server';

Now when you create a new build of the app, you will only see that the API request gets made once.

If you view the source of the server-side rendered page, you should see the application state as a snippet of JSON at the bottom of the page:

Figure 2.22: Viewing the source of the server-side rendered page
Figure 2.22: Viewing the source of the server-side rendered page