1

I have a react application which I bootstrapped using create-react-app. The application runs in a docker container, and has been deployed in a subdomain. Let's say the domain is http://mycompany.com , then I the react app is at http://mycompany.com/users/userid/apps/reactapp.

There is a reverse proxy server which does URL rewriting for changing the base URL to subdomain URL. This is how my package.json looks like -

{
  "name": "my-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.12.4",
    "@testing-library/jest-dom": "^5.16.1",
    "@testing-library/react": "^12.1.2",
    "@testing-library/user-event": "^13.5.0",
    "@types/classnames": "^2.3.1",
    "@types/jest": "^27.0.3",
    "@types/node": "^16.11.47",
    "@types/react": "^17.0.38",
    "@types/react-dom": "^17.0.11",
    "@types/react-icons": "^3.0.0",
    "@types/react-router-dom": "^5.3.2",
    "@types/sass": "^1.43.1",
    "bootstrap": "^5.1.3",
    "classnames": "^2.3.1",
    "font-awesome": "^4.7.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-icons": "^4.3.1",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.0",
    "register-service-worker": "^1.7.2",
    "typescript": "^4.5.4",
    "web-vitals": "^2.1.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "css-flatten": "^1.0.1",
    "react-hot-loader": "^4.13.1",
    "react-select": "^5.4.0",
    "sass": "^1.45.2"
  }
}

The issue I am facing is, any JS file changes are not getting reflected even after I restart the dev server using react-scripts start. It's only reflected if I restart the docker container. In browser, I have checked, the bundle.js file doesn't have the latest changes. I have tried these things already -

  1. Removing node_modules/.cache, node_modeules
  2. Use CHOKIDAR_USEPOLLING=true with react-scripts start

I can see in the dev server logs, that file changes are getting detected, but those changes are just not used to be served to the browser. Even when I delete a file ( as a result I can see error logs in the dev server logs), but still the application has no changes even on browser refresh.

Abhishek
  • 83
  • 10

2 Answers2

2

You may want to add the following to your server side response header

"headers": { 
    "/**": { 
        "Cache-Control": "no-store, no-cache" 
    } 
}

If the issue still persist, you can try clearing browser cache

Related question:

  1. Cache busting with CRA React
  2. ReactJS: How to prevent browser from caching static files?
Anay
  • 741
  • 1
  • 5
  • 15
1

Ok found the issue, there was a caching being done at the cloud gateway side, and because of that bundle.js file was getting cached. As there was no cache-control header set from webpack dev server for bundle.js, hence gateway treated this as a valid candidate for caching. It was working for html, because the gateway does not cache html pages.

Abhishek
  • 83
  • 10