Requestly
HTTP InterceptorPricingRequestly vs PostmanBlogDocsDownload

Home / Blog / Guides

How to add a Random Query Parameters to Prevent Caching?

This feature has been deprecated. You can learn more about it here.

Query parameters, also known as URL parameters or query strings, play a crucial role by facilitating the communication of data between clients and servers through the URL.

Many caching mechanisms consider the full URL (including query parameters) when determining whether to use a cached version or fetch a new one. If the URL changes, it’s often interpreted as a different resource, leading to a fresh request to the server.

By adding a random query parameter to the URL, you effectively make each URL unique. Since the query parameter is random, it changes with every request. This prevents the browser or caching proxy from serving a cached version because each request appears to be for a different resource due to the unique query parameter.

Using Requestly to avoid caching by adding random query parameter

We’ll be using Modify Query Parameter rule to add random query parameter.

  1. Download and Install the Requestly Chrome extension.
  2. Click on Create your first rule.
  3. Then select Query Param and click on Create rule.
  4. Add a param name -cache_buster with value rq_rand(1). Requestly supports rq_rand(X) as a predefined function which can be used to add a random number with X number of digits when you do a URL rewrite.
  5. Save the rule.

Using Requestly to avoid caching by adding random query parameter screenshot

By adding a random query parameter, you ensure that each request is treated as a unique resource, forcing the browser to fetch the latest version from the server. This is especially useful for developers who want to see their changes in real-time without having to clear the browser cache manually.

Test any API request visually: import a cURL command or build from scratch in Requestly, the free API client for developers.

Download Free →