Skip to content

Latest commit

 

History

History
47 lines (34 loc) · 1.22 KB

transfer-http.md

File metadata and controls

47 lines (34 loc) · 1.22 KB

TransferHttpCacheModule

TransferHttpCacheModule installs an Http interceptor that avoids duplicate HttpClient GET requests on the client, for requests that were already made when the application was rendered on the server side.

When the module is installed in the application NgModule, it will intercept HttpClient requests on the server and store the response in the TransferState key-value store. This is transferred to the client, which then uses it to respond to the same HttpClient requests on the client.

Any requests other than GET will prevent any further requests.

Usage

To use the TransferHttpCacheModule, first install it as part of the top-level App module.

import {TransferHttpCacheModule} from '@nguniversal/common';

@NgModule({
  imports: [
    BrowserModule.withServerTransition({appId: 'my-app'}),
    TransferHttpCacheModule,
  ],
  bootstrap: [MyApp]
})
export class AppBrowserModule() {}

Finally, in main.ts change this:

...

platformBrowserDynamic().bootstrapModule(AppBrowserModule);

To this:

...

document.addEventListener("DOMContentLoaded", () => {
  platformBrowserDynamic()
    .bootstrapModule(AppBrowserModule)
    .catch(err => console.log(err));
});