[Front End] Client-side rendering vs Server-side rendering
Do you ever wonder - what can a website not do? You can chat, play games, work on Google Doc.etc.
Server-Side Rendering
Traditional way of rendering a website.How it works?
- Server generates HTML files and sends it to browser (client), where it is displayed as a website.
- Doesn't matter if new page has one difference than the current page, the browser will ask for the entire page, and re-render everything.
Client-Side Rendering
Didn't become popular until JavaScript libraries started using this development style; examples are Vue.js and React.js
How it works?
- Instead of getting the generated HTML files from the server, you download the data you need, template HTML(s) and Javascript (libraries). Then, the browser renders the data into the template HTML using Javascript or Javascript Libraries.
- Server is responsible for less processing (doesn't need to generate the HTML) - this responsibility is pushed to the client (browser).
- When navigating through 2 similar pages, where only the data points are different, instead of requesting the entire HTML of the new page, the browser will request just the changes in the data. Then the browser will render the data into the template HTML.
- This is usually faster than Server-side rendering because there is less network traffic between client and server.
Comparisons
There is no clear answer as to whether Client-side or Server-side rendering is better. They both have their pros and cons, so we will explore how they are better than the other in different areas.
A: SEO (Search Engine Optimization)
Search engines work by crawling websites ahead of time and indexing them. They don't "read" a website like a human does, but rather, they access the DOM (Document Object Model). DOM is what you see when you "inspect element" in a browser.
In the past, the clear winner in this category is server-side rendering. That was when Search Engine crawlers could only read static html files. In 2015, Google released an announcement saying:
In the past, the clear winner in this category is server-side rendering. That was when Search Engine crawlers could only read static html files. In 2015, Google released an announcement saying:
Referencing a blog I found, it did tests into searching client-side rendered pages on popular search engines, such as Google, Yahoo, Bing, GoGoDuck.etc. In short, SEO does look into client-side rendered pages as well, but whether it prefers one over the other is in discussion."Times have changed. Today, as long as you're not blocking Googlebot from crawling your JavaScript or CSS files, we are generally able to render and understand your web pages like modern browsers. To reflect this improvement, we recently updated our technical Webmaster Guidelines to recommend against disallowing Googlebot from crawling your site's CSS or JS files." (https://webmasters.googleblog.com/2015/10/deprecating-our-ajax-crawling-scheme.html)
Furthermore, there are several ways a mis-configured client-side rendered page can make itself 'less' SEO. For example, if the search engine crawler is unable to access the Javascript, then it basically can't "read" the page.
The answer to "who's the winner" for this category is - "it depends".
The answer to "who's the winner" for this category is - "it depends".
B: Performance
There are 4 sections in performance to discuss:
- initial loading time
- overall loading time
- consistency across devices
- Interactivity
Firstly, the initial loading time on client-side rendered sites are usually longer, because the Javascript (library) has to be downloaded as well. Assuming the server is capable of the traffic, it is often faster for the server to generate the final HTML, than the browser (client).
Secondly, the overall loading time is often shorter on client-side rendered sites. Client-side rendered sites are often known as SPA (Single Page Applications) because they download all of the HTML files initially. By doing this, navigating to other pages within the website usually takes a shorter time because there's less data that needs to go to the server and back. Furthermore, when you have pages with a similar structure, a client-side rendered site will be much more efficient because it can dynamically load and unload data into the template HTML; it might need to do request for data from the server though. A server-side rendered site, in this situation, will have to do a HTML request from the server; which usually takes more time than just fetching data (client-side).
Thirdly, client-side rendered sites are usually less consistent in their performance, because a large part of the processing is done on the client-side (browser). The resources on the client-side will make a difference (eg. running the website on an old phone vs a gaming PC). On the other hand, in a server-side website, all the processing is done on the server. The browser only needs to display the HTML; which is not an intensive task.
Lastly, the coolest feature of client-side rendered sites is the immense amount of interactivity it has introduced to websites. Compare webpages today to the ones in the 2000s. Today, you can pretty much have anything running on a website; ranging from text editors (Google Doc) to multiplayer first-person shooters. While you can argue that this is due to increase in network speed and upgrades in Javascript libraries, all this will not be possible if the data isn't processed on the client-side.
I think the winner in this category is undecided. While you can have the largest scale website doing incredible things, it might not run a mobile phone because of inconsistent performance across devices. When a page does not run, it just "does not run"; the purpose of a website has failed.
I think the winner in this category is undecided. While you can have the largest scale website doing incredible things, it might not run a mobile phone because of inconsistent performance across devices. When a page does not run, it just "does not run"; the purpose of a website has failed.
Verdict
By now, you probably can guess the answer - "it depends". It really depends on what your website's purpose is for.
If your website is full of changes in structure or the scale of it is very small, then a server-side rendered site is probably a better solution. You can benefit from the consistent performance and fast initial load time. You don't need the re-usability of HTMLs or the intensive data processing and interactivity that client-side rendered sites offer.
However, if you are building the next amazon website or stock exchange website, then definitely, go for the client-side rendering solution as you will need the features of reusability of the html and site interactions offered by client-side rendering.
Sources:
- https://hackernoon.com/server-side-vs-client-side-rendering-in-react-apps-443efd6f2e87
- https://medium.freecodecamp.org/what-exactly-is-client-side-rendering-and-hows-it-different-from-server-side-rendering-bd5c786b340d
- http://openmymind.net/2012/5/30/Client-Side-vs-Server-Side-Rendering/
- https://medium.com/@adamzerner/client-side-rendering-vs-server-side-rendering-a32d2cf3bfcc
- https://moz.com/blog/javascript-seo
- https://www.quora.com/How-do-you-accomplish-SEO-with-a-client-side-framework-like-Backbone
Comments
Post a Comment