amplify-hosting
amplify-hosting copied to clipboard
Allow filtering query params for cloudfront policy or custom cloudfront policy
Environment information
N/A? Site is frontend SSG/SSR only with nextjs and no backends/amplify SDK used in the code.
Describe the feature
The managed cloudfront policies allow removing cookies from the cloudfront cache key. It would be useful to also be able to either completely ignore query params or ignore specific query params like you can with a custom cloudfront policy.
Alternatively allowing a completely custom cloudfront policy to be used would allow this setup.
Use case
With next.js (currently using v14), the default behavior is to prefetch links between pages when the link element is in the browser viewport. These requests have a _rsc query param added with a random token for the prefetch.
We have a docs site which doesn't have any query params except for the prefetch params on pages. The problem is all of the prefetches cache miss on cloudfront even if the page exists in cloudfront because of the query parameter. I think this would be solved by ignoring the _rsc query param in the cloudfront policy for the cache key.
We haven't been running the deployment long enough to see, but so far it seems like most of the pages don't benefit from caching (we're setting to 20 minutes with stale-while-revalidate) with the cookies disabled cache policy.
It is possible to disable prefetching as a workaround (although not at a global level in nextjs unfortunately), it just results in a slightly degraded user experience for page navigation.