nuxt-community / pwa-module

Zero config PWA solution for Nuxt.js
https://pwa.nuxtjs.org
MIT License
1.23k stars 171 forks source link

Cache API is caching image only if it's displayed in DOM #434

Closed Ratatinator97 closed 3 years ago

Ratatinator97 commented 3 years ago

Hello, I'm posting this here as I didn't got any answer on stackoverflow and think that it may belong here.

Setup

@nuxtjs/pwa: ^3.3.3 nuxt: ^2.14.12

Context

In my app every user can upload an image and view the uploaded images. (Sort of google photos). I wanted to implement an offline mode for my app. For now, only the images displayed are getting cached : <img class="image" :src="picto.path"/>.

I wanted that with only one button press cache all of the images. I tried to do make a GET request (with axios) for every image of the user : await axios.get("/image/"+image.path);.

Problem

Only a axios.get doesn't work. I don't know why but only the images I get AND THEN display are getting cached.

Answer

All I had since the beginning was the browser cache ! I found this very nice tutorial https://web.dev/offline-cookbook/ .