React JS
REACT JS, ANGULAR JS, VUE JS – THE 4W’S OF JAVASCRIPT (WHO, WHAT, WHY, & WHEN)
30th August 2022
10 minsReact is an open source frontend JavaScript library, which is created and maintained by the Facebook Developer Community. It is used to build User Interfaces or UI Components.
However, this definition might not be completely comprehensible to novices. We have the perfect blog post which walks you through a brief explanation of React, all the way up to a very detailed technical description of it, which you can find over here.
To understand what Server Side Rendering is, first it’s important to get an overview of how a webpage appears on your screen, which is elucidated by the diagram below:
This is a very big oversimplification of the journey of a webpage, but is a good enough preface into explaining the different sub steps and different ways (including Server Side Rendering) to accomplish this task.
Diving deeper into the process mentioned in the previous section, we have a technique known as Client Side Rendering or CSR, which has been in use since a long time, to display a website on user’s screens. This is explained in the following diagram:
As is clear with the steps mentioned above, from a user’s perspective, they can only see and interact with the website at the final step, after all the necessary files have been downloaded and rendered by the client machine.
This can take a huge amount of time as it is dependent on the performance of the client machine in executing the framework and parsing the JavaScript files.
Explaining it in a single line, Server Side Rendering or SSR is the process of taking a client side JavaScript framework website and rendering it to static HTML and CSS on the server instead of the client, as was the case in CSR.
Below mentioned is a pictorial representation of the journey a web page takes with Server Side Rendering, with React:
Thus, one of the biggest visual changes from the user’s perspective is that the web page becomes ‘visible’ pretty quick, as rendering HTML is not that resource intensive, talking from the browser’s perspective.
This doesn’t inherently make the page load faster than a non SSR app, but it does give the users the view of the web page as the JavaScript files download and parse in the background, after which the web page becomes interactive. This means that the TTI, i.e. Time To Interactive (this is the time it takes for the web page to be completely interactive from when the user requests the web page) is a bit more than the time it takes for the web page to be visible in the browser.
So, in an SSR scenario, for faster first render time, your HTML and CSS needs to be meaningful to the users, and JavaScript can be the enhancement for HTML and CSS, since its loading is deferred.
A common misconception about the workings of SSR with React is that after every change, such as a user requesting any new data, the server again completes all the steps and sends the HTML file with new UI to the browser, but this is not the case. Only a partial update to the page is done. Although the rendering is done by the server, the finalized output is inserted into the DOM by ‘hydrating’ it, as explained earlier.
React is an excellent choice to implement SSR because it incorporates the concept of a virtual DOM (Document Object Model).
This enables developers to create a virtual version of the React app, and have it in the server itself.
This makes it easier to render it to an HTML using the renderToString function as discussed earlier, send that down to the browser so that the browser can render it pretty quickly and create a virtual version on the client machine.
So, looking at the fact that this virtual version matches up with HTML we sent out from the server, React will not re-render it, thus decreasing the Time To Interactive (TTI), resulting in a ‘faster’ loading web page.
We wish there was a one size fits all solution for everything, but that is far from the case, especially with new technologies. Although SSR has tons of benefits, there are some cases as discussed earlier, for which SSR might not be a good choice; highly interactive sites being at the vanguard of it.
That’s where Creole Studios come in. We have an array of technology experts, always abreast with almost every new technology that pops up in the techverse. We will understand your business needs and provide you with customized solutions, be it an SSR or CSR app, and rest assured, you’ll have to worry about nothing while we do the heavy lifting for you. Contact us and get your ideas from your head into an app!
To calculate a ballpark estimate of your web or mobile app development costs, use this FREE Software development cost calculator.