Server Side Rendering with Angular Universal

What is Server-Side Rendering (SSR)

Server-side rendering (SSR), is the ability of an application to contribute by displaying the web page on the server instead of rendering it in the browser. Server-side sends a fully rendered page to the client. Server-side rendering (SSR) is a popular technique for rendering a client-side single page application (SPA) on the server and then sending a fully rendered page to the client. This allows for dynamic components to be served as static HTML markup.

Why we use Server-Side Rendering (SSR)?

-Search engine optimization (SEO). Plays an important role in SEO (search engine optimization) and correctly indexes webpages.

-Improve performance on web and mobile devices.

-Enables pages to load faster which provides a better user experience.

-It provides body to the HTML pages for all server ships.

-It assists with loading the page when the user has a slow internet connection.

Setting up Angular Universal in the Project to run the below command in the project folder. 

ng add @nguniversal/express-engine

This command will install the required packages and add some new files for setting up SSR

src/main.server.ts,

src/app/app.server.module.ts,

tsconfig.server.json,

webpack.server.config.js,

server.ts,

It will also update the following files accordingly:

package.json,

angular.json,

src/main.ts,

src/app/app.module.ts


After that Create one Home Component

As like we can update the Title and Description for a particular page in our application

No alt text provided for this image

Run the application and check the content of the web page using the below command.

npm run build:ssr && npm run serve:ssr




To view or add a comment, sign in

More articles by Sohan Paul

  • Signals in Angular: A Modern Approach to Reactive State Management

    Angular, one of the most widely adopted front-end frameworks, continues to evolve to meet the demands of modern web…

  • Implementing MicroFrontend in Angular

    MicroFrontend is a way of building web apps by dividing them into small, separate, and flexible parts called modules…

  • React Hooks

    React the popular JavaScript library for building user interfaces has undergone significant advancements over the…

  • Front-End Web Designer: Job Description and Skills

    Front-end web designers may be involved in building websites, but their responsibilities begin before the website is…

Explore content categories