2018-02-14 02:24 pm
Hello Everyone!
I wanted to take a moment to talk about a scenario that happens very often when doing web development. The scenario can cause all sorts of headaches, pains, and lost time. Often, the resolution seems like some sort of voodoo magic was applied when suddenly everything "just works."
The scenario is common. We are developing a new page or deploying a new version of the website and we are replacing some javascript, css, or image file. When we restart the webpage in our browser and attempt to see our glorious changes, much to our repeated chagrin, the site looks exactly as it had previously looked, and it seems as if our updates are just not working.
When this ugly scenario happens, we may spend hours of our time combing through our javascript code and/or trying to drop and recreate the images, or trying to figure out why our latest css styles are not being applied. No matter what we do, it can seem utterly hopeless, and so in an attempt to gain our sanity, we walk away from the system for a bit. When we return, or open the site in a different browser, suddenly everything works! Wow!
What just happened?
It's called "cache" and it got cleared, so that the resources were reloaded, thereby allowing our new javascript, images, and/or css styles to easily be correctly applied. Without us doing anything different, the site now works because the actual files we thought we were using are actually being used - whereas before the site was using a cached version of the site in our browser.
Before you get upset and wonder why we'd ever let this happen, please remember that cache is a great thing! Most of the time our files aren't changing, and cache prevents the users from having to reload everything each time they visit our pages. This speeds up the page and also limits the throughput that must take place on every web request.
So how can we make sure not to waste those hours again?
There are a couple of things we can do as web developers to make sure that this caching issue is not going to make our site appear to fail to update:
And how do I solve this problem on my local development machine?
As a local developer, however, there are two very easy solutions we can use to make sure that we don't get stuck with this problem any longer:
Finally, one thing I do is in the settings of the clear cache extension, I make sure to set the page to refresh:
Enjoy (and avoid the pain and headaches of bad cache in the future)!
Categories: : Tips and Tricks, Web Development, Caching