Alex Ironside
Alex Ironside

Reputation: 5049

Disabling caching in a built SPA

How it works: I build the app, and put it online using FTP. The problem is, the browsers cache the old version of my React app.

To use the new version I have to manually clear cache. Obviously, users will not know how to do it.

How can I disable the caching of my code?

I am using linuxpl.com hosting. I literately have no idea what I should include, if you need some info please let me know and I'll provide it.

Upvotes: 0

Views: 2269

Answers (2)

falinsky
falinsky

Reputation: 7428

To force a browser "clear" its cache you can generate unique file names every time you create a build.

If you use webpack for to create a production build - you can read more how to deal with it here.

Upvotes: 1

Sean D
Sean D

Reputation: 156

Your server can tell the browser not to cache items. In NGINX (or whatever you server is running), you'll want to add a header along the lines of

add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';

so that the browser knows to always fetch fresh versions.

Upvotes: 1

Related Questions