Today I Learned

TIL, 2023-11-29

Incremental Static Regeneration (ISR) In Next.Js

Reference

  • Create/serve pre-rendered pages on demand, balancing real-time updates and performance.
  • SSG: Generate all pages during the build process.
  • SSR: Generate each page on every request.
  • ISR: On each page, indicate how frequently the page should be regenerated in the background.

Benefits

  • Real-time update the stale pages in the background.
  • Personalised content - Generate personalised static pages based on the user-specific data.
  • SEO-friendly.
  • Developer experience.
  • Reduce cost for the build process.

Problems

  • Cache invalidation
  • If there are API calls, then the compatibility/synchronisation can be challenging.
  • Increased complexity.
  • Server load.

5 Lessons Learned From Taking Next.js App Router to Production

Reference

Multi-tenant repo - thoughts

  • No problems on authenticated fetches because we have user already.
  • Problem is on non-authenticated fetches like:
    • Bootstrap
    • Terms and conditions
    • Help center/static documents
  • Biggest change is moving the folder structure of the pages.
    • Long-term this allows us to move to full-route caching the pages (we are caching responses already anyway).
  • Middleware only is to add locale if there is no locale specified, and use negotiator to figure out what locale to add.
  • When we have locale in the params (not query params), we can access that anywhere in the server, even without the user.

Thoughts

  • ISR for pages that need to be updated frequently.
  • We are doing SSR now for the layout, and then SPA-style for the listing pages.
  • We are already caching Bootstrap/all responses via Next’s fetch API.

This project is maintained by daryllxd