Gatsby: [1.0] Client caching issues

Created on 17 Jun 2017  Â·  12Comments  Â·  Source: gatsbyjs/gatsby

Hey, congrats for the beta release! Things are moving fast. That's awesome.

Since I started using the offline and manifest plugins my site shows old data and sometimes errors... I messed a lot with it so I can't really trace back to a step by step reproducible problem but what I know is whatever the problem is, it gets resolved when I unregister service workers. Shouldn't this be done every time the user is online to make sure they get the latest data?

Most helpful comment

Did some work on this https://github.com/gatsbyjs/gatsby/pull/1217

If a user w/ sw navigates to a page it doesn't know it immediately reloads. Also when a new service worker is installed the page is reloaded. Makes for a bit of a "hiccup" but it's not too bad (loading from the sw is fast). We'll roll with this for a while and see how we like it.

All 12 comments

Yes :-)

I've been noodling over this the past week or so and I have a number of tweaks I'm going to be making to core & the offline plugin (as it's not just with SW this problem shows up though it's much more likely to show up with a SW).

Will report back early next week with a PR.

Did some work on this https://github.com/gatsbyjs/gatsby/pull/1217

If a user w/ sw navigates to a page it doesn't know it immediately reloads. Also when a new service worker is installed the page is reloaded. Makes for a bit of a "hiccup" but it's not too bad (loading from the sw is fast). We'll roll with this for a while and see how we like it.

Thanks Kyle, I'll check the result on my site today.

Okayyy. Feedback from my side: I had to manually refresh the page. So when landing on homepage then navigating to another page (with new content from last build) the site gave an error in the console. When I refresh manually, everything is fine.
I guess it may be related to the way I get my data on build (not through a plugin but a custom script) and/or the fact that I had the old sw...
I will report back in the coming days when my data change again.
Thanks again for the work

Yeah, this stuff is slow to test because you have to build to get the new sw then do another build to test the upgrade :-( took a while to build because of that.

I've been testing it via gatsbyjs.org upgrades and it seems pretty solid.

Thanks for testing! Please report back any problems or suggestions for improvements.

Hey. Just a small update confirming what I said above.

  1. Manual refresh is needed to get the new content. When checking the Gatsby website today I had to manually refresh to see the plugins page (I didn't think about looking in my console but I guess there was some red printing there)
  2. It seems that if new data is added with a custom script (not a plugin and not using Gatsby's API), it never shows even on manual refresh.
    -> My build: node fetchMyDataAndWriteInAJsonFile && gatsby build. I have a cron task to rebuild everyday on netlify. When doing so, data never shows. If I fetch locally then push to Github, it works alright though (except for 1.).

Obviously 2. is not a "real issue". It's on me if I don't use Gatsby's API.

Here is the console error when visiting Gatsby website today:
Failed to load resource: the server responded with a status of 404 ()
For files:
page-component---src-pages-docs-index-js-fe4698ea9f81f1bf0ef8.js &
app-b75066f8b2a017dd8b53.js
Refreshing solves it. Hopefully you know what to do with that @KyleAMathews ...?

@MarcCoet did the page refresh once the new service worker comes in?

The site is supposed to load from the service worker and have all the site resources cached there and then once a new SW comes in, it should reload immediately.

The only way I can happening what you saw is if the SW hadn't cached a file e.g. like there, the home page component, which is possible as right now since it's not precaching all page components.

Hey @KyleAMathews. Did I answer you somewhere else? I just found back this issue and noticed you were still hanging there. Crazy time for me, sorry.
For the record I still get a bunch of 404 when I visit gatsby website. The new service worker is coming ok but there's no reload.
I only tested in Chrome (2 different systems though).

I am also having this issue – load a new url with old sw in place, sent to 404, have to reload, re-navigate to original url

Was this page helpful?
0 / 5 - 0 ratings

Related issues

3CordGuy picture 3CordGuy  Â·  3Comments

totsteps picture totsteps  Â·  3Comments

hobochild picture hobochild  Â·  3Comments

jimfilippou picture jimfilippou  Â·  3Comments

mikestopcontinues picture mikestopcontinues  Â·  3Comments