blob: 73c7b3460fb53718be293d504f5f697cb005b813 [file] [log] [blame]
import ajaxCore from './ajaxCore';
function ajax(opts, callback) {
// cache-buster, specifically designed to work around IE's aggressive caching
// see http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/
// Also Safari caches POSTs, so we need to cache-bust those too.
var ua = (navigator && navigator.userAgent) ?
navigator.userAgent.toLowerCase() : '';
var isSafari = ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1;
var isIE = ua.indexOf('msie') !== -1;
var isEdge = ua.indexOf('edge') !== -1;
// it appears the new version of safari also caches GETs,
// see https://github.com/pouchdb/pouchdb/issues/5010
var shouldCacheBust = (isSafari ||
((isIE || isEdge) && opts.method === 'GET'));
var cache = 'cache' in opts ? opts.cache : true;
var isBlobUrl = /^blob:/.test(opts.url); // don't append nonces for blob URLs
if (!isBlobUrl && (shouldCacheBust || !cache)) {
var hasArgs = opts.url.indexOf('?') !== -1;
opts.url += (hasArgs ? '&' : '?') + '_nonce=' + Date.now();
}
return ajaxCore(opts, callback);
}
export default ajax;