Categories
JavaScript Answers

How to clear or replace a cached image with JavaScript?

Spread the love

Sometimes, we want to clear or replace a cached image with JavaScript.

In this article, we’ll look at how to clear or replace a cached image with JavaScript.

How to clear or replace a cached image with JavaScript?

To clear or replace a cached image with JavaScript, we call fetch.

For instance, we write

fetch("/thing/stuck/in/cache", { method: "POST", credentials: "include" });

to call fetch with the URL of image stuck in the cache by making a post request to it.

Then the image will be reloaded.

Conclusion

To clear or replace a cached image with JavaScript, we call fetch.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *