8000 GitHub - joocy/angular-ssr-demo · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Angular SSR Service Demo

This is a small Angular SSR demo. The /products route renders product data from an injectable service on the server before the browser runs Angular JavaScript.

The same component is also available at /products-csr, but that route uses client-side rendering. This makes it easy to compare the raw HTML for SSR and CSR in one project.

What To Look At

  • src/app/products/products.service.ts: returns the demo product data
  • src/app/products/products.ts: injects the service, stores data in signals, and derives summary values with computed
  • src/app/products/products.html: renders the signal values
  • src/app/app.routes.server.ts: sets /products to RenderMode.Server and /products-csr to RenderMode.Client
  • src/server.ts: allows local localhost requests for the demo server

Run The Demo

Build the browser and server bundles:

pnpm build

Start the SSR server:

pnpm serve:ssr:angular-ssr-service-demo

Open the page:

http://localhost:4000/products

Open the client-rendered comparison route:

http://localhost:4000/products-csr

Prove SSR Is Working

In another terminal, request the raw HTML:

curl -s http://localhost:4000/products

The response should already contain product HTML such as:

<h2>Mechanical keyboard</h2>
<h2>USB-C monitor</h2>
<h2>Wireless mouse</h2>

It should also contain ng-server-context="ssr" and a server render timestamp.

Compare With CSR

Request the client-rendered route:

curl -s http://localhost:4000/products-csr

That response should contain the app shell and scripts, but not the product list HTML yet. The browser downloads JavaScript, hydrates/boots Angular, and then renders the component on the client.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0