Caching Images with Cache Storage
Let's use the Cache Storage API to store images from products. Go to Menu.js
and add the following code to the load()
method at the end:
// Cache images
if (Menu.data) {
const imageCache = await caches.open("cm-images");
Menu.data.forEach(c=>imageCache.addAll(
c.products.map(p=>`/data/images/${p.image}`)
));
}
Check with DevTools that the images were cached.