CagriAldemir / react-cache-buster

This package allows clients to automatically check the new version when a new version is released in the production environment, and if a new version is published, clearing the cache and reload the page.
MIT License
60 stars 22 forks source link

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

Open balbo opened 1 year ago

balbo commented 1 year ago

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

tran302 commented 1 year ago

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

halfacandan commented 1 year ago

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);
...
sadik-malik commented 7 months ago

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?

sparrowek commented 5 months ago

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?