Serverless-next.js: Forwarding cookies & query parameters results in CloudFront misses

Created on 31 Dec 2019  路  3Comments  路  Source: serverless-nextjs/serverless-next.js

I've been noting a lot of cache misses from CloudFront. It seems it's due to forwarding all cookies & query parameters, even when there's no lambda involved (e.g. _next/* static html pages). From the code, it looks like this is hardcoded. Is this on purpose / is there a rationale about forwarding cookies for static pages?

Describe the solution you'd like
Configure cookies/query parameters to not be forwarded

Alternatively, #270 would solve this if there was some documentation added around required configuration for good cache performance.

Describe alternatives you've considered
If changing that by default is problematic, could it be configurable?

Additional context
Happy to make a pull request, with some suggestions around whether to change by default or make it configurable - just let me know the best approach here!

next component

Most helpful comment

This shouldn't be an issue anymore. You can now further customise the cloudfront distribution. Please see https://github.com/danielcondemarin/serverless-next.js#custom-cloudfront-configuration

All 3 comments

@AaronMoat _next/* requests are returned from cache (set to 86400 seconds). e.g.

image

image


It is true however that cookies are being forwarded for _next/* which it probably shouldn't.

For ssr and api page requests it is necessary to forward cookies for authentication / session cookies etc.

In terms of static pages generated by next's build, they could be cached in a more clever way, for which I'm currently looking into options.

Does that make sense?

Yeah, that makes sense. I was specifically talking about static pages - I was getting cloudfront misses constantly, on all assets, and then I turned off cookie/header forwarding manually and got cloudfront hits.

This shouldn't be an issue anymore. You can now further customise the cloudfront distribution. Please see https://github.com/danielcondemarin/serverless-next.js#custom-cloudfront-configuration

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mekwall picture mekwall  路  5Comments

Vadorequest picture Vadorequest  路  5Comments

patricktyndall picture patricktyndall  路  3Comments

vishwasnavadak picture vishwasnavadak  路  4Comments

gustavorps picture gustavorps  路  6Comments