const image = 'https://example.com/image.png;
const cname = 'testing-cache';
fetch(image)
.then(response => response.blob())
.then(blob => {
caches.open(cname)
.then(cache => cache.put(image, new Response(blob)));
});
caches.open(cname).then(cache => {
cache.match(image).then(response => {
if (response) {
response.blob().then(blob => {
const url = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img);
});
}
});
});
const image = 'https://example.com/image.png;
const cname = 'testing-cache';
fetch(image)
.then(response => response.blob())
.then(blob => {
caches.open(cname)
.then(cache => cache.put(image, new Response(blob)));
});
caches.open(cname).then(cache => {
cache.match(image).then(response => {
if (response) {
response.blob().then(blob => {
const url = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img);
});
}
});
});