Angular

Server-Side Rendering In Angular 11

In this article, we will learn how to implement server-side rendering in Angular 11 with angular universal.

We can build SEO friendly angular apps by the server-rendering our app with angular universal. Angular Universal technology can help to boost angular app’s performance.

Source – https://infographicworld.com

Why SEO is important?

SEO (Search Engine Optimization) is an important feature in any web application because they allow the web app to be discovered by social media networks and search engines.

Let’s see an example of how to do that,

Prerequisites:

  • Basic knowledge of Angular
  • Code editor like Visual Studio Code

Create a new Angular project by typing the following command in the VSCode terminal.

ng new seo-demo

Now, open the newly created project and execute the commands given below to set up Angular Universal.

ng add @nguniversal/express-engine --clientProject seo-demo

NOTE: The project name mentioned in the above command must be the same as the project name in angular.json.

The schematic will automatically add an express server and also the required configurations and packages. The express server will render a part of the Angular app and return HTML to the browser.

Now, let’s execute the commands given below to build or run an angular app with the express server.

npm run build:ssr
npm run serve:ssr

You can see the page source difference in output, before and after the server-side rendering build.

Output:

Please give your valuable feedback and if you have any questions or issues about this article, please let me know. Also when you build your existing project with server-side rendering, it may get fails because angular universal have some predefined rules. I will add a solution for some of the common errors related to angular universal/server-side rendering in my upcoming articles.

Also, check Drag & Drop Image Upload In Angular 10 With .NET Core

Yasin Panwala

Yasin Panwala is a Web Developer and Author at TheCodeHubs. He has experience in Web Developing and Designing and also in Writing. He has got his skills in working on technologies like .NET Core, ADO.NET, AJAX, Angular, AngularJS, ASP.NET, ASP.NET MVC, Bootstrap, C#, CSS, Entity Framework, Express.js, GraphQL, HTML, JavaScript, JQuery, JSON, LINQ, Microsoft Office, MongoDB, MySQL, Node.js, PostgreSQL, SQL, SQL Server, TypeORM, TypeScript, Visual Basic .NET, Web API. He also got his skills in working with different integration and some known versioning tools. He is always ready to learn new things and he always tries his best on tasks that are assigned to him and gives the best possible outputs.

View Comments

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

2 years ago