next-boost / next-boost

Add a cache layer for server-side-rendered pages with stale-while-revalidate. Can be considered as an implementation of next.js's Incremental Static Regeneration which works with getServerSideProps.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to filter out some headers from the cache

capJavert opened this issue · comments

We have a paramFilter config option which allows us to filter out some params that do not have impact on cache but in turn are important eg. utm_ params and such.

When working with analytics there is sometimes need to set custom cookies on initial request that then identify user across sessions. Those cookies do not impact the response of the page (or cache in that matter) in any way. Problem is that if we set cookies on server side then Set-Cookie header will be included inside the cache.

My proposition is that we add headerFilter config that would like paramFilter skip adding matched cookies to the cache.

I think it would be easy to integrate on this line before saving to cache:
https://github.com/next-boost/next-boost/blob/master/src/handler.ts#L80

I would be open to contribute to this if this makes sense?

@rjyo sorry to ping, any thoughts on this?

commented

@capJavert , that would be extremely useful. One of the cases of using getServerSideProps instead of getStaticProps is to be able to set some headers at response time. So it would be very useful to prevent this setting from being cached.