Angular generic - server-side cached requests for client

I have seen many articles about caching data for the client in generic angular apps, so it does not duplicate requests on the client that have already been resolved on the server.

I just don't understand how data is passed from server to client. Am I embedding JSON in preprocessed HTML or am I missing something else?

+3


source to share


1 answer


As of angular 5, inside the angular box there is a module called TransferStateModule

that does this for you. https://angular.io/api/platform-browser/TransferState

You just add your API response to the cache on the backend along with the StateKey (mostly as a string), it gets written to the DOM as Json, before the index.html file is sent to the client, there you request the StateKey and get the result from the Json.



In the official Universal Starter Kit, you can see where and what to register: https://github.com/angular/universal-starter

+2


source







All Articles