How to cache whole next.js's HTML page in Redis?

Viewed 769

I'm new to next.js. I'm trying to cache the whole HTML page in next.js. So, that I can reduce the response time in the next call for that page.

I tried by creating a custom server and then save the response that came from rendertoHTML()/render(). But it didn't return any response.

1 Answers

Redis is not for caching whole HTML pages or any other complex object types for that matter. It's key–value database. In Redis you should keep your object simple.

For your case it's best to use stale-while-revalidate (SWR) cache-control headers in combination with getServerSideProps for server-rendering in NextJS. See here for example.

Related