0

I am setting up a Cloudfront distribution for my companies website. We would like to set the caching time by using the Cache-Control headers on the server-side (Node.Js with Express), like this:

if (req.url.startsWith('/static')) {
   res.setHeader('Cache-Control', 'public,max-age=500');
}

At first, this seems to work well, but one of the criteria for the cache is failing, and that is, to ignore query string parameters.

For example, the request "domain.com/static/logo" and "domain.com/static/logo?foo=bar" should be interpreted as the same resource, and cached as one.

I wonder if it is possible to cache a resource while ignoring its query string parameters, using only the Cache-Control headers.

Thank you.

Rafael Marques
  • 1,335
  • 4
  • 22
  • 35
  • Possible duplicate of [How do browsers compare URLs for caching?](https://stackoverflow.com/questions/33204523/how-do-browsers-compare-urls-for-caching) – Joe Jun 03 '19 at 13:24

1 Answers1

1

Bydefault CloudFront does remove the query string and also doesn't consider it into the cache , this is a default behaviour of CloudFront so that there are not multiple cache copies based on different query string parameter. If you don't seem this behaviour, you may have "Query string" set to Forward all and cache based on call in CloudFront's cache behaviour.

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/QueryStringParameters.html

James Dean
  • 4,033
  • 1
  • 9
  • 18