Query String Sort best practise


We are setting up some filtering on our APIs and I had a question about taking advantage of Query String Sort: https://blog.cloudflare.com/increasing-cache-hit-rates-with-query-string-sort/

Take these two examples of multi selecting colours as a query parameter.


This sample we use a comma separated list of options, this has now split the cache. I can’t see how Cloudflare could sort this because to them red,blue is just a string and they can’t change the order incase that order means something to the API. This makes is less cacheable but keeps character count down.


This way I believe Query String Sort can work because it knows they are the same parameter but it can now be sorted alphabetically to ensure there is only one cache entry. However this also means a lot larger URL - which could run over the maximum size limit.

Personally I think /my/api?colour=red&colour=blue this option works, but I was just wondering if anyone had any comments here. I could not find any examples.


Query String Sort only sorts the keys as far as I know. You could use Workers + Cache API to sort query params with comma separated values, but that would of course add cost and complexity :slightly_smiling_face:

yeah thats an interesting idea thank you…
I’m considering making the api reject if they are not sorted… but if anyone else has any ideas let me know

1 Like

You would need a lot of parameters to go over the 32KB limit imposed by Cloudflare - at that point you should probably transmit options in another way.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.