-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
113 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,46 @@ | ||
# @ngx-ssr/cache | ||
|
||
Install package | ||
|
||
```bash | ||
npm i @ngx-ssr/cache | ||
``` | ||
|
||
Import the `NgxSsrCacheModule` module to cache all GET requests | ||
|
||
```ts | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { AppComponent } from './app.component'; | ||
import { NgxSsrCacheModule } from '@ngx-ssr/cache'; | ||
import { environment } from '../environments/environment'; | ||
|
||
@NgModule({ | ||
declarations: [AppComponent], | ||
imports: [ | ||
BrowserModule, | ||
NgxSsrCacheModule.configLruCache({ maxAge: 10 * 60_000, maxSize: 50 }), | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppModule { | ||
} | ||
``` | ||
|
||
HTML caching is also available for express | ||
|
||
```ts | ||
import { ngExpressEngine } from '@nguniversal/express-engine'; | ||
import { LRUCache } from '@ngx-ssr/cache'; | ||
import { withCache } from '@ngx-ssr/cache/express'; | ||
|
||
server.engine( | ||
'html', | ||
withCache( | ||
new LRUCache({ maxAge: 10 * 60_000, maxSize: 100 }), | ||
ngExpressEngine({ | ||
bootstrap: AppServerModule, | ||
}) | ||
) | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,37 @@ | ||
# @ngx-ssr/platform | ||
|
||
Install package | ||
|
||
```bash | ||
npm i @ngx-ssr/platform | ||
``` | ||
|
||
To determine the platform, use the tokens `IS_SERVER_PLATFORM` and `IS_BROWSER_PLATFORM` | ||
|
||
```ts | ||
@Directive({ | ||
selector: '[some-directive]', | ||
}) | ||
export class SomeDirective { | ||
constructor( | ||
@Inject(IS_SERVER_PLATFORM) isServer: boolean, | ||
) { | ||
if (isServer) { | ||
viewContainer.createEmbeddedView(templateRef); | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Use the `ifIsServer` and ` ifIsBrowser` structural directives in your template for rendering contents depending on the | ||
platform: | ||
|
||
```ts | ||
@Component({ | ||
selector: 'ram-root', | ||
template: '<some-сomp *ifIsServer"></some-сomp>', | ||
styleUrls: ['./app.component.less'], | ||
}) | ||
export class AppComponent { | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,29 @@ | ||
# @ngx-ssr/timeout | ||
|
||
Install package | ||
|
||
```bash | ||
npm i @ngx-ssr/timeout | ||
``` | ||
|
||
Use `NgxSsrTimeoutModule` to set timeouts for all requests | ||
|
||
```ts | ||
import { NgModule } from '@angular/core'; | ||
import { | ||
ServerModule, | ||
} from '@angular/platform-server'; | ||
import { AppModule } from './app.module'; | ||
import { AppComponent } from './app.component'; | ||
import { NgxSsrTimeoutModule } from '@ngx-ssr/timeout'; | ||
|
||
@NgModule({ | ||
imports: [ | ||
AppModule, | ||
ServerModule, | ||
NgxSsrTimeoutModule.forRoot({ timeout: 500 }), | ||
], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class AppServerModule { | ||
} | ||
``` |