Current section: Cookies 5 exercises

Implementing Optimistic UI for Theme Switching

Loading exercise


00:00 One of the drawbacks of our approach of requiring a network request to change the user's theme is that if their network is slow, their theme change is going to be slow. So let's go to a slow 3G. This is something that you just cannot control as a web developer. You don't get to

00:15 control the user's network speed. So if I click on this, we're going to be waiting around for a little while before the request response finishes and now we get our theme. That is super duper not cool. Not a fan of that at all. And so that would drive many people to just say,

00:32 okay, I'm just going to do a document.cookie thing and, you know, whatever. That's more complicated than it has to be. So we're going to be implementing some optimistic UI here and it's going to be sick. So I want you to go ahead and follow the instructions. The emoji will be there to guide your way through this. But yeah, we're going to make this optimistic. So even on a slow

00:52 network, clicking on this, you can click it rapidly and it will change every time. It will feel like everything is just happening in the client or that you're on like an ultra fast network or whatever. It'll feel really good for the user. And then, but we don't have to change the way that we're doing it. So we don't lose the benefits of the approach that we've taken

01:12 already. So give that a whirl and we'll see you when you're done.