{"id":58545,"date":"2023-09-18T07:25:57","date_gmt":"2023-09-18T01:55:57","guid":{"rendered":"https:\/\/www.tothenew.com\/blog\/?p=58545"},"modified":"2023-10-03T07:35:22","modified_gmt":"2023-10-03T02:05:22","slug":"mastering-dynamic-pre-rendering-elevating-seo-and-user-experience-with-prerender-io","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mastering-dynamic-pre-rendering-elevating-seo-and-user-experience-with-prerender-io\/","title":{"rendered":"Mastering Dynamic Pre-rendering: Elevating SEO and User Experience with prerender.io"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">This solution tackles the challenges of Client-Side Rendering (CSR), boosting both SEO performance and user experiences using dynamic pre-rendering with prerender.io. Learn how to set up and optimize this approach, improving SEO rankings and speeding up browser rendering for your website.<\/span><\/p>\n<h2><b>What is Client Side Rendering(CSR)?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">When a user makes a request to a domain or URL of any application from their browser, it sends a request to the server, which in turn sends the bare HTML markup and any JS bundle\/files required for rendering the web pages to the browser.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Now, Javascript runs on the client device(browser) to render the web pages. So basically, it all happens at runtime on the client machine itself. All working hunky dory and perfectly. However, a major issue a CSR application creates is bad SEO scores, as when different crawlers or bots try to crawl or read the data, they only get the bare HTML file and some of the metadata.<\/span><\/p>\n<h2><b>What Is Server Side Rendering(SSR)?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">As opposed to CSR, Server-side rendering (SSR) renders a web page on the server rather than on the browser.\u00a0 The user will get a fully rendered HTML page that will have all the necessary information without waiting to load JS, CSS, and other assets.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Pre-rendering or SSR generates static HTML snapshots of your pages, which are then served to bots and users<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So, when a user requests a page from a browser, a fully rendered page is served for viewing and interactions; it solves major issues like bad SEO scores and slow rendering experience of CSR applications and SPA\u2019s (Single page applications).<\/span><\/p>\n<h2><b>Dynamic Pre-rendering <\/b><b>&#8211;<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">When any browser sends a request for a web page to our server, it serves the pre-rendered HTML along with the JS for further executions and interactions on the client side. However, in the case of SEO, when a crawler or bot sends the request, it only receives the pre-rendered HTML data without the JS bundle. JS is not required for the bot as it doesn&#8217;t have any content for users.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This will make your SPA or CSR applications serve the pre-rendered data for both browsers and for bots.<\/span><\/p>\n<h2><b>How to pre-render your website?<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">For pre-rendering your application, there are a few ways available &#8211; <\/span><\/p>\n<h3><b>1. Static Site Generation (SSG)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">In this approach, a series of pages and content transforms into production-ready static HTML files at build time. These are basically provided inbuilt into frameworks and tools like Gatsby, next.js, Hugo etc Using these frameworks makes it easy to implement and develop websites using SSG.<\/span><\/p>\n<h3><b>2. Pre-rendering Services<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">In this, we have some online services that provide pre-rendering to applications that don\u2019t have an inbuilt pre-rendering functionality eg. <\/span><a href=\"http:\/\/prerender.io\/\"><span style=\"font-weight: 400;\">prerender.io<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here, we will be looking into one of the pre-rendering services \u2018prerender.io\u2019 to achieve dynamic pre-rendering.<\/span><\/p>\n<h2><b>Prerender.io <\/b><b>&#8211;\u00a0<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">We will be using the prerender.io server and middleware, making minor changes to enable pre-rendering for both browsers and bots. Additionally, we will ensure that no script tags are removed when a request comes from a browser.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Prerender.io is just one of many options for achieving pre-rendering. One can look into other options as well.<\/span><\/p>\n<h2><b>Execution-<\/b><\/h2>\n<ol>\n<li><b> Setup the pre-render server using prerender.io\u00a0<\/b><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><a href=\"https:\/\/github.com\/prerender\/prerender\"><span style=\"font-weight: 400;\">https:\/\/github.com\/prerender\/prerender<\/span><\/a><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">In <\/span><b>server.js <\/b><span style=\"font-weight: 400;\">change server variable to <\/span>&nbsp;<\/li>\n<\/ul>\n<pre style=\"text-align: left;\"><span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 var server = prerender({<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0chromeFlags: [<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0'--headless',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 '--disable-gpu',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 '--remote-debugging-port=9223',<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0'--hide-scrollbars'<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0});\u00a0<\/span><\/pre>\n<p>&nbsp;<\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Changes in <\/span><b>removeScriptTags.js<\/b><span style=\"font-weight: 400;\"> to check if <\/span><b>\u2018user-agent\u2019<\/b><span style=\"font-weight: 400;\"> is any bot, then only remove the script tags and continue with the script tags.<\/span><\/li>\n<\/ul>\n<ol start=\"2\">\n<li><b> Setting up the middleware file<\/b><\/li>\n<\/ol>\n<ul>\n<li>Use prerender-node middleware of prerender.io and change it as per your use case.<\/li>\n<li><span style=\"font-weight: 400;\">Make the <\/span><b>prerender<\/b><span style=\"font-weight: 400;\">.<\/span><b>shouldShowPrerenderedPage<\/b><span style=\"font-weight: 400;\"> function always return true.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Adding \u2018.json\u2019 in <\/span><b>prerender<\/b><span style=\"font-weight: 400;\">.<\/span><b>extensionsToIgnore<\/b><span style=\"font-weight: 400;\"> Array.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Save this file as prerenderNode.js.<\/span><\/li>\n<\/ul>\n<ol start=\"3\">\n<li><b>\u00a0Setting up the node server for serving our SPA using Node and express<\/b><\/li>\n<\/ol>\n<ul>\n<li><span style=\"font-weight: 400;\">Import the middleware(prerenderNode.js) we created in step 2.<\/span><\/li>\n<li>Import prerenderNode from &#8216;.\/prerenderNode.js&#8217;;<\/li>\n<li><span style=\"font-weight: 400;\">Set the prerenderServiceUrl and pass the URL of the prerender server created in step 1.\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p><b>\u00a0app.<\/b><b>use<\/b><b>(<\/b><b>prerenderNode<\/b><b>.<\/b><b>set<\/b><b>(<\/b><b>&#8216;prerenderServiceUrl&#8217;<\/b><b>, <\/b><b>&#8216;URL OF PRERENDER SERVER\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 CREATED IN STEP 1&#8217;<\/b><b>))<\/b><b>;<\/b><\/p>\n<p><b>Conclusion<\/b><b>:<\/b><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-58544\" src=\"\/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-300x159.png\" alt=\"\" width=\"610\" height=\"323\" srcset=\"\/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-300x159.png 300w, \/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-1024x542.png 1024w, \/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-768x407.png 768w, \/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-1536x813.png 1536w, \/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM-624x330.png 624w, \/blog\/wp-ttn-blog\/uploads\/2023\/09\/Screenshot-2023-09-14-at-12.28.15-PM.png 1632w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><\/p>\n<h3><b>Flow for a User:<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\"><b>User&#8217;s Browser:<\/b><span style=\"font-weight: 400;\"> The user enters the URL in their web browser and initiates a request to your server.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Server Processing:<\/b><span style=\"font-weight: 400;\"> Your server receives the request and serves the pre-rendered HTML along with the JavaScript and other assets required for rendering the web page.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Client-side Rendering:<\/b><span style=\"font-weight: 400;\"> JavaScript runs on the user&#8217;s device (browser) to further render and enhance the web page, providing interactivity and dynamic content.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Fully Rendered Page:<\/b><span style=\"font-weight: 400;\"> The user sees and interacts with the fully rendered page.<\/span><\/li>\n<\/ul>\n<h3><b>Flow for a Bot (Search Engine Crawler):<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\"><b>Bot&#8217;s Request:<\/b><span style=\"font-weight: 400;\"> A search engine crawler (bot) sends a request to your server, typically with a specific user agent indicating it&#8217;s a bot.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Server Processing:<\/b><span style=\"font-weight: 400;\"> Your server detects the bot&#8217;s request and serves the pre-rendered HTML specifically for bots. This HTML contains the essential content and metadata but may lack some interactive features reliant on JavaScript.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Bot&#8217;s Indexing:<\/b><span style=\"font-weight: 400;\"> The bot processes the pre-rendered HTML, indexes the content, and stores it in search engine databases for later retrieval by search queries.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">By serving pre-rendered HTML to bots, you improve the chances of your content being indexed effectively by search engines, which can positively impact your site&#8217;s SEO.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Embrace dynamic pre-rendering through prerender.io to seamlessly bridge the gap between SEO optimization and enhanced user experiences, ensuring your web application thrives in both search rankings and performance benchmarks<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While dynamic pre-rendering can offer significant benefits, there are some downsides and considerations to keep in mind:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>Increased Server Load:<\/b><span style=\"font-weight: 400;\"> Pre-rendering can put additional load on your server, especially if you have a large number of pages to pre-render. You need to ensure that your server infrastructure can handle the increased requests and resource demands.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Maintenance Overhead:<\/b><span style=\"font-weight: 400;\"> Managing pre-rendering configurations and ensuring they stay up-to-date with changes in your application can be an ongoing task. Any updates or changes to your site&#8217;s structure or content may require corresponding adjustments to your pre-rendering setup.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Costs:<\/b><span style=\"font-weight: 400;\"> Some pre-rendering services may come with associated costs, depending on your usage. Factor in these costs when considering whether to implement dynamic pre-rendering.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Caching Challenges:<\/b><span style=\"font-weight: 400;\"> Caching pre-rendered pages can be more complex than caching fully client-rendered pages. You need to manage caching strategies carefully to ensure that users receive up-to-date content.<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>Complexity:<\/b><span style=\"font-weight: 400;\"> Implementing dynamic pre-rendering can add complexity to your development and deployment processes. It may require changes to your build pipeline and deployment scripts.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">To mitigate these issues, it&#8217;s important to thoroughly plan your pre-rendering strategy, and test it extensively. Additionally, monitoring tools and regular SEO audits can help identify and address any duplicate content or indexing issues that may arise.<\/span><\/p>\n<div class=\"ap-custom-wrapper\"><\/div><!--ap-custom-wrapper-->","protected":false},"excerpt":{"rendered":"<p>This solution tackles the challenges of Client-Side Rendering (CSR), boosting both SEO performance and user experiences using dynamic pre-rendering with prerender.io. Learn how to set up and optimize this approach, improving SEO rankings and speeding up browser rendering for your website. What is Client Side Rendering(CSR)? When a user makes a request to a domain [&hellip;]<\/p>\n","protected":false},"author":1101,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":68},"categories":[3429,1185,5270,4488],"tags":[5431,5430,5429,5433,404,5432],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/58545"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/1101"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=58545"}],"version-history":[{"count":2,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/58545\/revisions"}],"predecessor-version":[{"id":58930,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/58545\/revisions\/58930"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=58545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=58545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=58545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}