Namespace: Urls:addCacheBuster

Urls:addCacheBuster

Source:

Methods

addCacheBuster(urlopt, paramNameopt, nullable) → {String}

Adds a cache busting parameter to a given URL. If there is already a parameter of that name, it will be replaced. This prevents legacy browsers from caching requests by changing the request URL dynamically, based on current time.

Parameters:
Name Type Attributes Default Description
url String | URL <optional>
null

the URL to add the cache busting parameter to, if nullish, the current URL will be used

paramName String <optional>
<nullable>
'_'

the name of the cache busting parameter

Source:
See:
Throws:

error if url is not a usable URL

Returns:
the transformed URL with the added cache busting parameter
Type
String
Example
addCacheBuster('https://foobar.com');
=> 'https://foobar.com?_=1648121948009'
addCacheBuster('https://foobar.com?next=https%3A%2F%2Ffoo.bar', 'nocache');
=> 'https://foobar.com?next=https%3A%2F%2Ffoo.bar&nocache=1648121948009'