Skip to content

Commit

Permalink
Add support for no-cache and no-store via a cache-busting querystring…
Browse files Browse the repository at this point in the history
… parameter
  • Loading branch information
JakeChampion committed Jul 9, 2020
1 parent a0783a5 commit a0dcd85
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fetch.js
Expand Up @@ -358,6 +358,21 @@ export function Request(input, options) {
throw new TypeError('Body not allowed for GET or HEAD requests')
}
this._initBody(body)

if (this.method === 'GET' || this.method === 'HEAD') {
if (options.cache === 'no-store' || options.cache === 'no-cache') {
// Search for a '_' parameter in the query string
var reParamSearch = /([?&])_=[^&]*/
if (reParamSearch.test(this.url)) {
// If it already exists then set the value with the current time
this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime())
} else {
// Otherwise add a new '_' parameter to the end with the current time
var reQueryString = /\?/
this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime()
}
}
}
}

Request.prototype.clone = function() {
Expand Down

0 comments on commit a0dcd85

Please sign in to comment.