{"id":2357,"date":"2025-10-01T15:00:37","date_gmt":"2025-10-01T22:00:37","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=2357"},"modified":"2025-10-01T15:00:38","modified_gmt":"2025-10-01T22:00:38","slug":"server-side-rendering-ssr-or-ssg-whats-the-difference","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/server-side-rendering-ssr-or-ssg-whats-the-difference\/","title":{"rendered":"Server-side rendering: SSR or SSG, what&#8217;s the difference?"},"content":{"rendered":"\n<p>I&#8217;ve covered <a href=\"https:\/\/blog.angulartraining.com\/introduction-to-server-side-rendering-with-angular-7c0ce70971b4\" target=\"_blank\" rel=\"noopener\" title=\"\">server-side rendering<\/a> in the past, but recently realized that people get confused about SSR and SSG.<\/p>\n\n\n\n<p>What&#8217;s the difference? SSR stands for <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>S<\/strong>erver-<strong>S<\/strong>ide\u00a0<strong>R<\/strong>endering, and it does what it says: when requested, an Angular route is<\/span> rendered on the server before being sent to the client as HTML syntax. <\/p>\n\n\n\n<p>Then, the browser loads Angular&#8217;s JavaScript code, and the process of <strong>hydration<\/strong> starts: Angular takes over the &#8220;static&#8221; DOM built from our server and hooks its component code to it. In other words, front-end JavaScript takes over from that point on.<\/p>\n\n\n\n<p>SSG stands for <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>S<\/strong>tatic<strong>\u00a0S<\/strong>ite\u00a0<strong>G<\/strong>eneration, and the process is very much the same as SSR, with one significant difference: SSG is performed at build time<\/span>, not at runtime. This is important for several reasons:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The pre-rendered SSG pages can be generated weeks, if not months, before being displayed in a browser, which means they can display stale data. They don&#8217;t get updated after that last <strong>ng build<\/strong>, though Angular will take over and hydrate them on load, just like with SSR.<\/li>\n\n\n\n<li>SSG doesn&#8217;t require a Node.js server, but SSR does. The build output of SSG can be used as-is and deployed to any web server, like a regular client-side Angular app.<\/li>\n<\/ol>\n\n\n\n<p>Now, how to choose between the two options? Well, the good news is that it doesn&#8217;t have to be the same choice for all routes. In an SSR app, a server-side router config is generated, and that file can be tweaked to do SSR, SSG, or even just client-side rendering based on the route:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"828\" height=\"654\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.50.39.png\" alt=\"\" class=\"wp-image-2358\" style=\"width:697px;height:auto\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.50.39.png 828w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.50.39-300x237.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.50.39-768x607.png 768w\" sizes=\"auto, (max-width: 828px) 100vw, 828px\" \/><\/figure>\n<\/div>\n\n\n<p>The above example makes perfect sense: An about page doesn&#8217;t change between builds. It can be pre-rendered with SSG.<\/p>\n\n\n\n<p>A profile page depends on user data, so this doesn&#8217;t make sense to pre-render at build time. SSR or client-side rendering are the two best options.<\/p>\n\n\n\n<p>Last but not least, what if we want to pre-render routes that use parameters? We can do so by adding a list of param values to pre-render routes with the <strong>getPrerenderParams<\/strong> function:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"691\" height=\"309\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.56.43.png\" alt=\"\" class=\"wp-image-2359\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.56.43.png 691w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2025\/10\/Screenshot-2025-10-01-at-17.56.43-300x134.png 300w\" sizes=\"auto, (max-width: 691px) 100vw, 691px\" \/><\/figure>\n<\/div>\n\n\n<p>The above example would have the Angular compiler pre-render the routes for <em><strong>\/post\/1\/foo\/3<\/strong><\/em> and <strong><em>\/post\/2\/bar\/4<\/em><\/strong> at build time. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve covered server-side rendering in the past, but recently realized that people get confused about SSR and SSG. What&#8217;s the difference? SSR stands for Server-Side\u00a0Rendering, and it does what it says: when requested, an Angular route is rendered on the server before being sent to the client as HTML syntax. Then, the browser loads Angular&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,39],"tags":[],"class_list":["post-2357","post","type-post","status-publish","format-standard","hentry","category-angular","category-server-side-rendering"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=2357"}],"version-history":[{"count":1,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2357\/revisions"}],"predecessor-version":[{"id":2360,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/2357\/revisions\/2360"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=2357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=2357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=2357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}