-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
49 lines (40 loc) · 1.67 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h4>Service worker</h4>
<video controls id="service-worker-video" height="300px" style="margin-right: 18px;" crossorigin="anonymous"></video>
<br />
<h4>Blob url</h4>
<video controls id="blob-video" height="300px" style="margin-right: 18px;" crossorigin="anonymous"></video>
<script>
const main = async () => {
await navigator.serviceWorker.register('./service-worker.js').then(() => {
console.log('loaded')
}).catch(console.error)
const handle = await caches.open('modfy-assets')
await fetch('/media/YDGHmx1p6_aHjcfk-m9OR.mp4', {headers: {}}).then(async (response) => {
const req = new Request({url: '/api/asset/YDGHmx1p6_aHjcfk-m9OR.mp4', headers: {'X-Modfy-Fetched-File': 'true'}})
await handle.put(req, response)
console.log('added to cache')
}).catch(console.error)
const videoElm = document.getElementById('service-worker-video')
videoElm.src = '/api/asset/YDGHmx1p6_aHjcfk-m9OR.mp4'
console.time('time to make blob')
const req = new Request({url: '/api/asset/YDGHmx1p6_aHjcfk-m9OR.mp4', headers: {'X-Modfy-Fetched-File': 'true'}})
const res = await handle.match(req)
const blob = await res.blob()
console.log(URL.createObjectURL(blob))
console.timeEnd('time to make blob')
const videoElm2 = document.getElementById('blob-video')
videoElm2.src = URL.createObjectURL(blob)
}
main()
</script>
</body>
</html>