Loading...


Related Products


Date Published: March 8, 2022

How to make Varnish ignore a URL's query string for front-end application use

Scenario

You have a front-end (e.g. Javascript) application that responds on a specific endpoint/URL and reads/writes arguments from the URL for its logic/state. Since the logic is executed on the front-end, you want the page to be served from Varnish (regardless of arguments) as there is no need to make a request to the back-end for each variation of the URL.

For the purposes of this example let's say the endpoint/URL is /myapp

Problem

/myapp
/myapp?arg1=value1
/myapp?arg1=value1&arg2=value2

... will all be needlessly cached as different entries in Varnish, after having needlessly hit the back-end once, and when

/myapp?arg1=value1&arg2=value2&arg3=value3

comes along, the same will happen. What we want is for Varnish to "ignore" everything after /myapp

Solution

Configure your front-end application to read/write the arguments as a URI fragment instead of GET request arguments.

That is, replace the first "?" with "#" making the previous requests look like:

/myapp
/myapp#arg1=value1
/myapp#arg1=value1&arg2=value2
/myapp#arg1=value1&arg2=value2&arg3=value3

With this URL structure all the above pages would be cached/served as a single entry in Varnish as browsers will not send the URI fragment to the server.

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation