What is Cache Buster? Why do you need it?

Published on Sep 20, 2022

by Jonas Alves

Web browsers use cache buster codes to prevent the browser from caching the same file twice. Web browsers upload fresh files to replace older files that have been viewed and saved. Caches expire slowly, so cache-busting can help ensure that end-users can access updates to a file. It is important to understand how browser caches work and how they are used.

What is Cache Busting?

When a user visits a website, the browser will ask if the user wants to allow cookies. If the user accepts the cookies, the browser will keep track of them and save them for a long time. The user will now be able to access the previously cached site whenever they return to the website. In the meanwhile, if the website has undergone updates, the user will be unable to access them.

The latter is true because, in order to take advantage of caching, the user's browser keeps a static copy of the webpage in his local storage. The problem can be remedied, though, if you utilise cache buster on your website. Cache busters solve the problem of browser caching by generating a unique URL.

How does a Cache Buster work?

Instead of preventing the browser from caching the file, a cache buster prevents the browser from reusing the old version. Every time a website is loaded, the cache buster inserts a random number into the ad tag. Because the ad calls are disguised as random numbers, the browsers are unable to link the tags to the files they have cached on the users' PCs. As a result, the browser feels obligated to call the origin server again. Cache busting allows you to boost publisher inventory, keep an image's relevance and purpose, and narrow the gap between publisher and marketer delivery information. Cache busters accomplish this through the usage of code.

How does Cache Buster Codes look Like?

Generally, in cache buster, there is a javascript version that looks like this: <script type="text/javascript" language="JavaScript">

ord=Math.random()*10000000000000000;

</script>

Adding this code to above the website's *body> tag will generate a spontaneous digit for the "ord" value in the ad label. Therefore, when a browser creates a tag, it will develop the ad tag in this way: 

http://ad.doubleclick.net/ABC/publisher/zone;topic=abc;sbtpc=def;cat=ghi;kw=xyz;tile=1;slot=728x90.1;sz=728x90;ord=7268140825331981?

Later, if the browser comes back to the same page in the future, the tag will look like this:

http://ad.doubleclick.net/ABC/publisher/zone;topic=abc;sbtpc=def;cat=ghi;kw=xyz;tile=1;slot=728x90.1;sz=728x90;ord=6051834582234?

Everything will be the same except for the numbers which will always be random.

What is the Objective of a Cache Buster?

With a cache buster, website owners can easily register for the right number of impressions in a marketing campaign. For the same reason, many big advertisers use cache buster codes, which can differ from one ad server to another. To learn more about how to use cache busting, read the following section.

Cache busting on your website is helpful for the users and for you as well. because you can use it to provide visitors with the most recent updates to your website. And it won’t require the users to perform any hard refresh or even clear the cache history from the browser. Developers like to use cache-busting tools to make the updated files available to everyone as soon as they are released. There are some popular methods you can apply to make use of cache-busting:

  • Versioning of file names

  • Query strings

  • Versioning of file paths

The most prevalent cache-busting approaches are file path and file name versioning, which do not break any caching mechanisms while also making it simple to reflect updates in web pages. Query strings, on the other hand, are notorious for producing cache issues. Files written with query strings are typically not cached by proxies or CDNs. Furthermore, if your website is slow and you run a speed test, you will be advised to eliminate query strings in order to speed it up. As a result, if you can, utilise more cache-busting with file names and file path versioning. However, regardless of which strategy you choose, be sure to change the HTML that refers to the cache-busting file.

How to use Cache Busting with CDN?

When using CDN cache-busting, there may not be much to configure in terms of file path versioning or file names, but query strings can be ignored or allowed by the CDN, and in that case, you can perform many options to configure the cached file. You can either ignore the query strings in CDN or if the Ignore Query String option is enabled, the CDN will view the requests, taking into account that there is no query string to view. Therefore, the cache will be returned with a cached version of the asset regardless of how similar the query strings are.

However, if you don’t enable the Ignore Query String option, then CDN will accept all the query string variations and it will act as if each of the strings is an individual. And in that case, you will have to request the following URLs:

https://example-hexid.kxcdn.com/style.css

https://example-hexid.kxcdn.com/style.css?ver=1

https://example-hexid.kxcdn.com/style.css?ver=2

Each of these variations will be cached by the CDN separately even after the origin comes with the same answer. But we don’t recommend you disable the Ignore Query String option because here the cache is messed up with multiple versions of the same cache file, which might not be necessary for caching.

What were the Challenges of Caching?

Consider the following scenario: your website has three files: index.js, index.html, and index.css, and the cache lifespan is one year. This indicates that a browser can save your website's cache for one year, allowing your site to load quickly in your user's browser. However, because your website's cache duration is one year, past users will not notice the new update if you replace the index.js file with numerous colour schemes. Users will have to wait a year for the new version to appear in their browser. This is the sole issue with caching, and it is here that cache buster comes in handy.

Conclusion: Why does a Browser need Caches? 

The server of the website sends the browser an HTML file that contains instructions on how to format the page and how to retrieve the images, text, and other elements. Downloading this file consumes both time and the user's device's memory. As a result, the browser saves as much time and space as possible by storing cache instead of cookies. Cache files are temporarily stored on the user's hard drive. The cache will make your site faster for sure, but the new updates and designs will not be noticeable. So, if you use a cache buster, it will help you keep your users around with not only impressive designs but also the same response time as before. 

Home

Benefits

Resources

About

Pricing

Benefits

Resources

About

Pricing