DEV Community

loren-michael
loren-michael

Posted on

Rendering: Half-Full or Half-Empty?

Today I was working on a lab for my Flatiron courses and noticed a note:

"Pessimistic rendering is recommended."

Well what the heck does that mean? Is my program feeling low? Down? Defeated? (Sometimes I do when I hit a snag, but that's no reason for the program to feel that way...)

I quickly learned that there are two different forms of rendering:

  • Pessimistic
  • Optimistic

In today's world of instant gratification, users generally don't want to wait for anything to load. It's understandable - with fast internet and apps that are designed for delivering information fast, we've just gotten used to it. When you are coding, it's smart to keep this in mind, because often you will discover changes you can make that will update your DOM but won't necessarily require you to reload/refresh your entire page. This kind of rendering is referred to as Optimistic, because it assumes that the server will update the database with the new information and doesn't depend on having to go through another load and fetch and render to display the new information. It simply says, 'oh, I see that you like this. I trust my program will update the database for you, so I'll just mark down your like really quick so you can continue browsing."

On the flip side, the pessimistic way of rendering these changes involves the rigmarole of sending a patch, reloading the page, fetching the new data, rendering everything all over again... it's not very trusting of your program and though it might not take a very long time, any time spent reloading might allow the user a moment to turn their attention elsewhere.

Optimistic rendering is obviously more desirable if you're trying to keep the user's attention on your program, but there are pros and cons to each style. Optimistic approaches work best with pretty simple tasks - tasks like "liking" things. When you get into more complicated tasks, like filling out forms or making a purchase, that's when you need the functionality of pessimistic rendering. It will be more accurate and dependable than making a visual change and hoping that it saved in the back-end.

Discussion (0)