Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Server-Side Enterprise Development with Angular

You're reading from   Server-Side Enterprise Development with Angular Use Angular Universal to pre-render your web pages, improving SEO and application UX

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher
ISBN-13 9781789806267
Length 142 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Bram Borggreve Bram Borggreve
Author Profile Icon Bram Borggreve
Bram Borggreve
Arrow right icon
View More author details
Toc

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
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime