Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cacheable-response for ssr #6393

Merged
merged 5 commits into from
Feb 27, 2019
Merged

Use cacheable-response for ssr #6393

merged 5 commits into from
Feb 27, 2019

Conversation

Kikobeats
Copy link
Member

Hello,

I have been using next.js for a while in a bunch of projects, so first for all thanks for all the vibrant effort around the project 🖤.

Always I see the server side next.js approach as an advantage, but also a weakness for the extra resources you need to have, specially comparing how cheap is a client side app.

In order to do my things cheaper, I started using the SSR pattern you suggested in your examples, so useful! It saves time and resources.

However, it was too simple. In a real production scenario, you need a bit more, specially related with send the right response headers to keep the rest of external network agent updated of your cache state.

I started a tiny script code for doing that; basically, I copy/paste it on my ssr projects.

Now, after a time, I think it's worth it publish it as cacheable-response module.

The PR is for adding the module leverage into the next.js ssr example.

It's doing the same, plus:

  • be possible use a multi storage cache (memory by default; mongodb, redis, mysql, supported).
  • sending cache-control response headers.
  • sending X-Cache-Expired-At, just a humanize way to see the expiration time.
  • support for forcing invalidation via force=true query parameter.

I hope you like it 🙂

@timneutkens
Copy link
Member

Should the state-while-revalidate be configurable here: https://github.com/Kikobeats/cacheable-response/blob/master/index.js#L25

@Kikobeats
Copy link
Member Author

@timneutkens good catch!

I shipped cacheable-response@1.1.0 that support it, also added etag response header.

@timneutkens timneutkens merged commit 3998805 into vercel:canary Feb 27, 2019
@Kikobeats Kikobeats deleted the ssr branch February 27, 2019 15:33
@lock lock bot locked as resolved and limited conversation to collaborators Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants