Normalize query string parameters - Amazon CloudFront
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Normalize query string parameters

You can normalize query string parameters to improve the cache hit ratio.

The following example shows how to improve your cache hit ratio by putting the query strings in alphabetical order before CloudFront forwards requests to your origin.

function handler(event) { var qs=[]; for (var key in event.request.querystring) { if (event.request.querystring[key].multiValue) { event.request.querystring[key].multiValue.forEach((mv) => {qs.push(key + "=" + mv.value)}); } else { qs.push(key + "=" + event.request.querystring[key].value); } }; event.request.querystring = qs.sort().join('&'); return event.request; }