create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Static files are cached and loading from service worker

Open vnoitkumar opened this issue 7 years ago • 5 comments

When I do any changes in my CSS file and do a build, a new CSS bundle file is created.

Build One

b1

Console.log of Build One

c1

Build Two

b2

Console.log of Build Two

c2

If you see in the second build the CSS file name is changed from main.1012bf29.chunk.css to main.2ff4e3dd.chunk.css

But if you see the console log for both the build is same, the CSS file of the first build is cached.

Expected output: On every build, the cache needs to be cleared.

Note: I have enabled PWA in my react app. React version is 16.7.0, I have created my project using the create-react-app command

vnoitkumar avatar May 28 '19 17:05 vnoitkumar

This isn't a bug I don't think. Read this section from the docs for details on why you're probably seeing this.

heyimalex avatar May 28 '19 17:05 heyimalex

I think the index.html file is cached and even after so many changes, I took a build, even then the old CSS files are getting loaded. If I do a hard refresh or clearing the cache it is working. How can I solve this problem?

vnoitkumar avatar May 28 '19 17:05 vnoitkumar

From the documentation I linked:

After the initial caching is done, the service worker lifecycle controls when updated content ends up being shown to users. This means that users will end up seeing older content until they close (reloading is not enough) their existing, open tabs. See this blog post for more details about this behavior.

So it's expected that it wont update until all tabs are closed. I personally disable service worker support because it's difficult to debug and understand. You can still make use of caching via your webserver without using any of the included PWA stuff.

heyimalex avatar May 28 '19 18:05 heyimalex

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Jun 27 '19 19:06 stale[bot]

This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.

stale[bot] avatar Jul 02 '19 20:07 stale[bot]