Use cacheable-response for ssr #6393
Merged
+14
−56
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
cache-control
response headers.X-Cache-Expired-At
, just a humanize way to see the expiration time.force=true
query parameter.I hope you like it 🙂