17

Bootstrapped with create-react-app (v1.0.13). Whenever I update the source & redeploy users need to hard refresh to get the new content. I've included non-cache header in index.html:

<meta http-equiv="Cache-Control" content="no-store" />

& turned off provided service workers. Also change the .js filename (and reference in index.html) in build folder before deploying.

Brad Woods
  • 1,507
  • 2
  • 12
  • 30
  • 1
    Disable caching or use a chunkhash so a changed file will have a new name – Julian Sep 06 '17 at 16:32
  • https://github.com/facebookincubator/create-react-app/issues/2328 – Julian Sep 06 '17 at 16:36
  • that's not a solution, just a link that goes to another link that goes deep into webpack which is something create-react-app helps to avoid. – Brad Woods Sep 06 '17 at 23:48
  • It is not an answer, only a comment that it is currently not implemented. And a link to an issue with an article how to use chunkhashs with webpack. – Julian Sep 07 '17 at 16:06
  • create-react-app does change the .js file name every time you make a build. The link you provided is just talking about making the filenames follow correct versioning. Not relevant to the problem. – Brad Woods Sep 07 '17 at 21:31
  • ok, but if every file (except .html) has a different name after it is changed there should be no problem with caching these files – Julian Sep 07 '17 at 22:13
  • I agree, that's why I posted this question. – Brad Woods Sep 07 '17 at 22:24
  • I ran into a similar issue, and this answer was the most helpful: https://stackoverflow.com/a/48738828/2136562 – Dagobert Renouf Oct 08 '18 at 14:36

2 Answers2

3

I was able to remove caching by doing the following:

  • adding the following to in index.html <meta http-equiv="Pragma" content="no-cache" /> <meta http-equiv="Expires" content="0" />
  • inserting the following to the js import { unregister } from './registerServiceWorker'; unregister()
  • changing cloudflare caching expiration to 'respect existing headers' at https://www.cloudflare.com/a/caching/

It is unclear which of these (or all of these) are actually required but it's a start.

Brad Woods
  • 1,507
  • 2
  • 12
  • 30
0

For anyone coming in the future -- all you need is the

{unregister} from ./registerServiceWorker

unregister();

This helped my create-react-app work with hosts like gh-pages and netlify.