K
K
Keppp2020-02-29 22:09:00
JavaScript
Keppp, 2020-02-29 22:09:00

How to remove caching?

When you reload the page, the image is loaded the same every time. But if you check cache dissabled in devtool, then the pictures are different.
How to make so that the pictures were different in and without a check mark? I understand the problem is in the cache.

const getCat = () => {
    const img = document.createElement('img');
    img.classList.add('cat__img');
    fetch('https://cataas.com/cat')
    .then(response => response.blob())
    .then(blob => {
        img.src = URL.createObjectURL(blob);
    });
    return img
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Pavel Kuzyakin, 2019-07-12
@Posho

<script src="/socket.io/socket.io.js"></script>
here are the sockets

E
Eugene Chefranov, 2019-07-12
@Chefranov

So at the beginning of the article, he installs npm install --save socket.io
And then connects<script src="/socket.io/socket.io.js"></script>

A
Alexander Cheremkhin, 2020-02-29
@Che603000

Disable cache via http headers

const options  ={
    headers: {
       "Cache-Control":" no-cache",
       "Pragma":" no-cache"
    }
};
const getCat = () => {
    const img = document.createElement('img');
    img.classList.add('cat__img');
    fetch('https://cataas.com/cat', options);
        .then(response => response.blob())
        .then(blob => {
            img.src = URL.createObjectURL(blob);
        });
    return img
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question