Skip to content
Advertisement

how load video only once if a modal is dynamic in vuejs3/vite?

I having a problem optimizing the performance of my application build in Vuejs3/Vite and Aframe. I need to somehow prefetch 6 videos. The problem is that each time I open a modal the browser fetches a video again. I want the browser to only fetch it once and store it somehow.

My application should look like this. Homepage has 6 buttons. On click, each button opens a modal. Inside the modal there a 6 videos. So, when a user clicks on the 2nd button the modal opens and inside it is only the 2nd video playing automatically. When a user clicks on a “close” button the modal is closed and the video is paused.

Right now my code looks like this: HTML template

JavaScript

My JS:

JavaScript

Here what my network tab look like after I restart the page and open a modal. The initial load is red. The modal open is green. network tab

What I’ve tried so far: Instead of v-if I made it work with v-show because with v-if it is not fetched at all.

To sum it all up, how do I make a browser only load a video once and cache/store it.

Advertisement

Answer

Wrapping your component with <keep-alive> should work:

JavaScript

DOCS

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement