Gonzalez
Gonzalez

Reputation: 31

Reactjs client needs to force refresh after deploy

Every time that a new deploy is made to production or any other environment the client needs to force a refresh and clear cache with ctrl shift r to updated the UI, the project was made with Create-React-App.

Already added the meta tags to HTML file but didn't work

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

Is there any kind of config I'm missing?

Upvotes: 3

Views: 5372

Answers (4)

nicolas.hacala
nicolas.hacala

Reputation: 56

Your src/index.js file should look like this

import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
serviceWorker.register();

Just change the

serviceWorker.register();

For

serviceWorker.unregister();

Upvotes: 2

Ahammed K M
Ahammed K M

Reputation: 376

Which version of CRA are you using? If it's caused due to ServiceWorker then you should disable the ServiceWorker.

import { unregister } from './registerServiceWorker';

unregister();

Upvotes: 0

Ilkin Nazarov
Ilkin Nazarov

Reputation: 17

Try this one, maybe you need cache control

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'> 

OR read this one https://webpack.js.org/guides/caching/

Upvotes: 0

Waled Ahmad
Waled Ahmad

Reputation: 73

add meta tags inside the head tag to make sure that the content of the page isn’t cached.

<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

Upvotes: 0

Related Questions