What is Server-Side Rendering10 min read

What is Server-Side Rendering? How Does It work?

Server-side rendering (SSR) is the capacity of an application to turn HTML files stored on the server into a fully rendered HTML page that is displayed to the user. The web browser sends a request for information to the server, which answers very instantaneously by delivering the client a completely displayed page that has been completed.

In order to improve Search Engine Optimization, search engines can crawl and index content before it is delivered to the user. Angular server side rendering, ejs server side rendering, server side rendering Express, Gatsby server side rendering, Google server side rendering, NestJS server side rendering, Next server side rendering, Nuxt server side rendering, React server side rendering, and Vue server side rendering are just a few examples of popular server-side rendering JavaScript frameworks.

 

Server-Side Rendering Definition

Server-side rendering refers to an application’s capacity to display a web page on the server rather than in the browser, which is referred to as client-side rendering. A fully rendered page is given to the client when the JavaScript on a website is rendered on the website’s server, and the client’s JavaScript bundle activates and enables the Single Page Application framework to execute.

What is Server-Side Rendering

What Are the Advantages of Rendering on the Server Side?

The following are some of the benefits of server-side rendering:

  • Pages load faster with a server-side rendered application, which improves the user experience.
  • Because material may be generated before the page is loaded, search engines can simply index and crawl content when rendered server-side, which is perfect for SEO.
  • Web sites with faster load speeds are prioritised by web browsers, so they are correctly indexed.
  • Server-side rendering speeds up the loading of webpages for users with sluggish internet connections or old devices.
  • What Are the Risks of Rendering on the Server Side?

The following are some of the drawbacks of server-side rendering:

  • Because server-side rendering is not the norm for JavaScript websites, and the server bears the complete load of generating content for users and bots, it can be costly and resource-intensive.
  • While rendering static HTML on the server is efficient, due to the bottleneck, rendering larger, more complicated apps on the server might increase load times.
  • Third-party JavaScript code may not be compatible with server-side rendering.
  • Server-side rendering may be perfect for static site generation, but in more complicated applications, frequent server calls and entire page reloads can result in overall slower page rendering.

Rendering on the server vs. rendering on the client

Rather than obtaining all of the material from the HTML document, client-server rendering renders content in the browser using the client-side JavaScript library. When a new page is loaded, the browser does not send a new request to the server. Because the information is not rendered until the page is loaded on the browser, search engine rankings may be harmed; however, website rendering is typically faster in client-side generated apps. When deciding between server-side and client-side rendering, the developer will examine the scope of the project, the application’s complexity, the number of users, and the user experience priorities.

What is server-side rendering and how does it work?

The most prevalent way for presenting information on the screen is server-side rendering. It operates by transforming HTML files on the server into browser-readable data. When you visit a website, your browser sends a request to the server that stores the website’s content. The request normally takes only a few milliseconds, however, this is dependent on a number of factors:

  • Your internet connection speed
  • To mention a few factors, the server’s location, the number of visitors attempting to access the site, and how well-optimized the site is.

Your browser receives the fully rendered HTML and displays it on the screen once the request has been processed. If you then go to a different page on the website, your browser will issue a new request for the updated information. This will happen every time you visit a page for which your browser hasn’t cached a version. The browser will request the complete new page and re-render everything from the ground up, even if the new page just has a few elements that are different from the existing page. Consider this HTML page, which has been uploaded to a hypothetical server with the URL example.testsite.com.

<!DOCTYPE html>

<html>

<head>

<meta charset=”utf-8″>

<title>Example Website</title>

</head>

<body>

<h1>My Website</h1>

<p>This is an example of my new website</p>

<a href=”http://example.testsite.com/other.html.”>Link</a>

</body>

</html>

If you type the address of the example website into the URL bar of your imaginary browser, the browser will send a request to the server associated with that URL, expecting a response of some text to render on the screen. The title, the content of the paragraph, and the link would all be visible in this scenario. Let’s pretend you wanted to click on a link on the displayed page that included the code below.

<!DOCTYPE html>

<html>

<head>

<meta charset=”utf-8″>

<title>Example Website</title>

</head>

<body>

<h1>My Website</h1>

<p>This is an example of my new website</p>

<p>This is some more content from the other.html</p>

</body>

</html>

The only difference between this page and the previous one is that this one lacks a link and instead contains a new paragraph. Only the new content should be rendered, and the remainder should be kept alone, according to logic. Unfortunately, server-side rendering does not work in this manner. What would actually happen is that the entire new page, not just the updated content, would be rendered.

While it may not appear to be a huge concern in these two cases, most websites are not as straightforward. Modern websites are far more complicated, with hundreds of lines of code. Consider reading a website and having to wait for each page to load as you navigate the site. You’ve probably seen how slow WordPress sites can be if you’ve ever visited one. One of the reasons for this is because of this. On the plus side, server-side rendering is beneficial to search engine optimization. Because your material is already there before you get it, search engines can easily index and crawl it. This is not the case with client-side rendering. At the very least, not easily.

What is client-side rendering and how does it work?

When developers talk about client-side rendering, they’re talking about utilising JavaScript to render content in the browser. Instead of getting all of the content from the HTML document, you’ll get a stripped-down HTML document with a JavaScript file that will render the remainder of the site in the browser. This is a relatively new method of rendering websites, and it didn’t gain traction until JavaScript libraries began to include it in their development methodology.

Vue.js and React.js are two famous examples, which I’ve written more about here. Assume you now have an index.html file with the following lines of code on the previous website, example.testsite.com.

<!DOCTYPE html>

<html>

<head>

<meta charset=”utf-8″>

<title>Example Website</title>

</head>

<body>

<div id=”root”>

<app>

</app>

</div>

<script src=”https://vuejs.org”type=”text/javascript”>

</script>

<script src=”location/of/app.js”type=”text/javascript”>

</script>

</body>

</html>

When rendering with the client, you can notice that the index.hmtl has undergone some significant changes. For begin, you have a container div with the id root instead of having the content inside the HTML file. Above the ending body tag, you have two script elements. One will load the Vue.js JavaScript library, while the other will load the app.js file. This differs from server-side rendering in that the server is now just responsible for loading the essential elements of the page.

The most important boilerplate. Everything else is handled by bespoke JavaScript code and a client-side JavaScript library, in this instance Vue.js. You would obtain a blank screen if you made a request to the URL using only the code above. Because the real content must be produced using JavaScript, there is nothing to load.

To fix that, you would place the following lines of code into the app.js file.

 

var data = { title:”My Website”, message:”This is an example of my new website” }

Vue.component(‘app’, { template: ` <div> <h1>{{title}}</h1>

<p id=”moreContent”>{{message}}</p>

<a v-on:click=’newContent’>Link</a> </div> `,

data: function() { return data; },

methods:{ newContent: function(){ var node = document.createElement(‘p’);

var textNode = document.createTextNode(‘This is some more content from the other.html’);

node.appendChild(textNode);

document.getElementById(‘moreContent’).appendChild(node);

} } })

new Vue({ el: ‘#root’, });

If you go to the URL now, you’ll see the same thing you saw in the server-side example. The main difference is that the browser will not send another request to the server if you click on the link on the page to load more content. Because you’re using the browser to render the items, JavaScript will be used to load the new content, and Vue.js will ensure that just the new content is rendered. Everything else will be left to its own devices. This is substantially faster because you are only loading a small portion of the page instead of the complete page to fetch the new material.

However, there are certain drawbacks to adopting client-side rendering. Because the content is not rendered until the browser loads the page, the website’s SEO will suffer. There are workarounds, but they aren’t as simple as with server-side rendering. Another thing to remember is that your website/application will not be able to load until the browser has downloaded ALL of the JavaScript. This makes sense because it has all of the necessary information. It’s possible that your users’ initial loading time will be prolonged if they have a slow internet connection.

The advantages and disadvantages of each method

That’s all there is to it. The fundamental distinctions between server-side and client-side rendering are as follows. Only you, the developer, can choose the best choice for your website or app. The following is a quick rundown of the advantages and disadvantages of each approach:

What is Server-Side Rendering

Pros on the server side

  • The ability for search engines to index the site for better SEO.
  • The page loads faster at first.
  • It’s ideal for static websites.
  • Cons on the server side: frequent server requests.
  • Overall, the page rendering is slow.
  • The entire page reloads.
  • Interactions between non-rich sites.
  • It speeds up website loading for a better user experience.
  • It gives all server pages body.
  • It helps sluggish internet users load pages faster.
  • It helps load pages on old devices.
  • Also, it accurately indexes pages and helps with SEO. Google favours websites that load quickly.

Client-side benefits include:

  • Interactions on the web are plentiful.
  • After the initial load, the webpage renders quickly.
  • Excellent for web-based apps.
  • A large number of JavaScript libraries are available.

What is Server-Side Rendering
Cons on the client’s side:

  • If not done appropriately, SEO will suffer.
  • It’s possible that the initial load will take longer.
  • In most circumstances, an external library is required.
  • Server-side rendering appears easy, but it becomes more challenging as the application becomes more complex.
  • Because it is a single bottleneck, rendering a large application on the server can take a long time.

 

Rate this post

Leave a Reply