Skip to main content

Server Side Cache

Cache server side

With Next.JS, React applications can be rendered isomorphic and delivered on the server side (SSR). So the time that elapses before the web server transmits the first byte of the page, increases rapidly i.e. TTFB.

React Server Side rendering is very costly and takes a lot of server's CPU power for that. One of the best solutions for this problem is cache already rendered pages.

As this can be solved by the infrastructure way but NextJS using custom express server can also provide ways to optimize the caching of static or dynamic routes/ pages.


/* Passing `cacheable-response` instance as middleware */

server.get("/", (req, res) => ssrCache({req, res, pagePath: "/"}))
  • This limit can be extended
  • Root ("/") is only configured to utilize this cache but can be extended to other routes too.
  • Can also be turned on/off per environment.