Server Side Rendering (SSR)
When using Server Side Rendering you would want to avoid double data load for same page. To atchieve this you have to do two steps:
Save state when on server
Load state when on browser
this can be attchieved in your app.module.ts
like:
Lets break this code
saveState
method saves all state changes until on serverloadState
method checks if saved state exists and if so loads it and merges onto the store and setsdataRestoredFromSSR
to true. After we listen to page finish loading event in order to setdataRestoredFromSSR
back to false.
dataRestoredFromSSR allows us to prevent all http calls until page is loaded - meaning that we will not hit server with repetetive requests for data that has been already loaded and restored.
Our http requests might look like this
Last updated