Static Site Generation

Pros and cons of Static Site Generation (SSG)

Which sites can leverage static-site generation

With Static Site Generation (SSG), HTML content is pre-generated and deployed as static files. The output is a set of immutable HTML, CSS and JS files.

The server does zero computation per request. Whenever the code or content changes for one or more pages, a build process runs to regenerate the HTML.

Normally, when working with static site generation, we create an automated workflow that builds and deploys the site whenever the content changes. Pure SSR however; it's not suitable with large-scale dynamic data. In a site with thousands of products, the problem becomes the build-to-deploy latency.

Static site

Some frameworks have already introduced new features to minimize build times and handle data updates more efficiently:

  • GatsbyJS - Incremental builds
    This feature optimizes performance by building only the pages that have changed since the last deployment.
  • NextJS - Incremental Static Regeneraton (ISR)
    It allows you to update static pages after you’ve built your site. It builds and caches pages at runtime as requests come in, providing the speed of static with the flexibility of dynamic.

Benefits of statically generated sites

  • Fast Server Response: Since files are pre-built, the server delivers them instantly without processing time.
  • Traffic Resilience: These sites handle traffic spikes with ease because serving flat files requires minimal resources.
  • Reduced Overhead: They deliver content without the need for real-time computation or database queries.
  • Compute Load: By removing the "compute" step from the user request, you eliminate the most common performance bottlenecks: server CPU/RAM usage and latency.

Disadvantages of static sites

  • No Dynamic Content: Because pages are pre-generated, they cannot serve user-specific content.
  • Delayed Updates: Content is not updated instantly; for very large sites, the regeneration task may be slow to reflect changes.

For rapidly changing content, a standard build process may not be fast enough. In these situations, Server-Side Rendering (SSR) or Client-Side Rendering (CSR) should be leveraged to ensure users see the most up-to-date information.

CAKE®STACK

Rolling With The Dough