Server side requests cached for client
I've seen many articles about caching data for client in angular universal apps, so it doesn't duplicate the requests on client that has been already resolved on server.
I just don't get how the data is transferred from server to the client. Do I inject the JSON to pre-rendered HTML or am I missing something else ?
As of angular 5, there is a module inside angular core called TransferStateModule
that does this for you. https://angular.io/api/platform-browser/TransferState
You simply add your API response to the cache on serverside together with an StateKey (basically just like a string), it get's written to the DOM as Json before the index.html file is send to the client, there you ask for 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
链接地址: http://www.djcxy.com/p/31362.html上一篇: Google Analytics /客户端专用代码
下一篇: 服务器端请求为客户端缓存