Skip to content
Eugene Lazutkin edited this page Nov 26, 2019 · 6 revisions

bust is a helper to generate a randomized query value to bust a browser's cache.

Don't forget to consult the cookbook to see working snippets solving simple real-world problems.

The main API

bust doesn't provide an elaborate API. Instead it updates io to include this functionality. Two helper properties and one options property are defined.

In order to use it, it should be included. No other action is required.

options.bust

This property allows you to opt-in a cache-busting. If it is truthy, its value is interpreted like that:

  • true — in this case io.bustKey is used to form a cache-busting query value. See below for more details.
  • a string — the value to use as a query key.

If options.bust is falsy, an I/O request would not use an automated cache-busting. If options.bust is truthy, cache module will not cache a request result.

io.bustKey

A string, which is used as a cache-busting query key. It can be overridden to customize the default case. Default: "io-bust".

You can always supply a cache-busting key value on a per request basis by specifying options.bust as a desired non-empty string.

io.generateTimestamp(options)

I function that actually generates a randomized value to be used with a query key. It takes one parameter: options object. Default implementation returns a current timestamp (generated by new Date().getTime()) as a string, and a random value (generated by Math.floor(Math.random() * 1000000)) as a string, separated by "-".

This function is exposed so it can be overridden to customize a cache-busting value.

Clone this wiki locally