134
rated 0 times
[
137]
[
3]
/ answers: 1 / hits: 16408
/ 8 Years ago, sun, january 29, 2017, 12:00:00
I have an offline app that caches all static resources. Currently, only the first 15 seconds of video assets are cached.
Below shows basic implementations of the install
and fetch
event listeners.
Service Worker:
self.addEventListener('install', event => {
event.waitUntil(
caches.open('v1').then(cache => {
return cache.addAll([
'/',
'/videos/one.mp4',
'/videos/two.mp4'
]);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
if (response) return response;
return fetch(event.request);
});
);
});
And in index.html
<video controls preload>
<source src=/videos/one.mp4 type=video/mp4>
</video>
More From » html