N
N
n1ksON2020-01-03 00:10:28
React
n1ksON, 2020-01-03 00:10:28

How to cache an image?

Image paths come via the API, in the component I render like this:

const Poster = ({ result }) => {
  return (
    <>
      {result.path ? (
        <img
          src={`https://image.tmdb.org/t/p/w300${result.path}`}
          alt="Изображение"
        />
      ) : (
        <></>
      )}
    </>
  );
};


Because of this, the image is reloaded with each render (even if the path has not changed). How to fix it?
That is, how to stop loading the image again after each render if the path has not changed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-01-03
@n1ksON

If everything is correct in the server response header, if the image name matches, and if the cache is not forcibly disabled on the browser side, the image, and indeed any other resource, should be taken from the browser cache.
5ff186d16bf32858981164.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question