react-cache-buster icon indicating copy to clipboard operation
react-cache-buster copied to clipboard

Assumption "XHR requests are not kept in the cache" not always true

Open balbo opened this issue 2 years ago • 4 comments

Looks like the assumption "XHR requests are not kept in the cache" on which react-cache-buster is based it's not always true. Maybe adding a timestamp can do the trick.

const res = await fetch(`${getMetaFileDirectory()}/meta.json?${Date.now()}`);

immagine

balbo avatar Nov 18 '22 10:11 balbo

Hello, is this going to be addressed? I am also having similar issues.

tran302 avatar Mar 28 '23 12:03 tran302

I manually applied the fix suggested by @balbo to this file and it fixed everything: node_modules\react-cache-buster\dist\index.js:69

/meta.json?${Date.now()}

    try {
      var _temp2 = _catch(function () {
        return Promise.resolve(fetch(getMetaFileDirectory() + `/meta.json?${Date.now()}`)).then(function (res) {
          return Promise.resolve(res.json()).then(function (_ref2) {
            var metaVersion = _ref2.version;
            var shouldForceRefresh = isThereNewVersion(metaVersion, currentVersion);
...

halfacandan avatar Aug 09 '23 20:08 halfacandan

I have fixed it by using the following in entry file for app

if (typeof window !== 'undefined') {
  const { fetch: originalFetch } = window
  window.fetch = async (...args) => {
    const [resource, ...rest] = args

    let modifiedResource = resource
    if (resource === '/meta.json') {
      modifiedResource = `/meta.json?v=${Date.now()}`
    }
    const response = await originalFetch(modifiedResource, ...rest)
    return response
  }
}

Is someone still maintaining this library?

sadik-malik avatar Mar 11 '24 11:03 sadik-malik

Maybe the problem is that it is the GET request which might be cached, so changing it to the POST request will solve the problem?

sparrowek avatar May 07 '24 10:05 sparrowek