What is @angular/platform-server?
@angular/platform-server is an Angular package that enables server-side rendering (SSR) for Angular applications. It allows you to render Angular applications on the server, which can improve performance, SEO, and user experience by delivering fully rendered pages to the client.
What are @angular/platform-server's main functionalities?
Server-Side Rendering (SSR)
This feature allows you to render an Angular application on the server. The `renderModule` function takes an Angular module and renders it to a string, which can then be sent to the client.
const { renderModule } = require('@angular/platform-server');
const { AppServerModule } = require('./src/main.server');
renderModule(AppServerModule, {
document: '<app-root></app-root>',
url: '/'
}).then(html => {
console.log(html);
});
Preboot
Preboot is a library that works with Angular Universal to record and playback user events while the client-side app is loading. This code sample demonstrates how to set up a global window and document object using the 'domino' library to enable Preboot.
const { renderModule } = require('@angular/platform-server');
const { AppServerModule } = require('./src/main.server');
const { createWindow } = require('domino');
const win = createWindow('<html><head></head><body><app-root></app-root></body></html>');
global['window'] = win;
global['document'] = win.document;
global['navigator'] = win.navigator;
renderModule(AppServerModule, {
document: win.document,
url: '/'
}).then(html => {
console.log(html);
});
Transfer State
Transfer State allows you to transfer state from the server to the client, reducing the need for duplicate HTTP requests. This code sample shows how to import and use the ServerTransferStateModule in your server-side module.
import { NgModule } from '@angular/core';
import { ServerModule, ServerTransferStateModule } from '@angular/platform-server';
import { AppComponent } from './app.component';
import { AppModule } from './app.module';
@NgModule({
imports: [
AppModule,
ServerModule,
ServerTransferStateModule
],
bootstrap: [AppComponent],
})
export class AppServerModule {}
Other packages similar to @angular/platform-server
next
Next.js is a React framework that enables server-side rendering and static site generation. It provides a similar SSR functionality to @angular/platform-server but is designed for React applications. It also includes features like API routes, automatic code splitting, and more.
nuxt
Nuxt.js is a framework for Vue.js that enables server-side rendering and static site generation. It offers similar SSR capabilities to @angular/platform-server but is tailored for Vue.js applications. Nuxt.js also provides features like automatic routing, Vuex store integration, and more.
sapper
Sapper is a framework for Svelte that provides server-side rendering and other advanced features. It offers similar SSR functionality to @angular/platform-server but is designed for Svelte applications. Sapper also includes features like file-based routing and prefetching.
19.0.2 (2024-12-04)
compiler-cli
| Commit | Type | Description |
| -- | -- | -- |
| 9f99196d23 | fix | account for multiple generated namespace imports in HMR (#58924) |
core
| Commit | Type | Description |
| -- | -- | -- |
| 4792db9a6d | fix | Explicitly manage TracingSnapshot lifecycle and dispose of it once it's been used. (#58929) |
migrations
| Commit | Type | Description |
| -- | -- | -- |
| 7b5bacc228 | fix | class content being deleted in some edge cases (#58959) |
| d1cbdd6acb | fix | correctly strip away parameters surrounded by comments in inject migration (#58959) |
| e17ff71c31 | fix | don't migrate classes with parameters that can't be injected (#58959) |
| 7c5f990001 | fix | inject migration aggressively removing imports (#58959) |
| 4392ccedf9 | fix | inject migration dropping code if everything except super is removed (#58959) |
| 9cbebc6dda | fix | preserve type literals and tuples in inject migrations (#58959) |
platform-server
| Commit | Type | Description |
| -- | -- | -- |
| f3c388ecda | fix | remove peer dependency on animations (#58997) |
<!-- CHANGELOG SPLIT MARKER -->
<a name="18.2.13"></a>