Skip to content

Commit cafc836

Browse files
committed
use minicoi for headers on ghpages
1 parent 50bb30a commit cafc836

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/pages/index.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Content as Description } from "../content/challengeDescription.md";
77
<!doctype html>
88
<html lang="en">
99
<head>
10+
<script src=`${import.meta.env.BASE_URL}/mini-coi.js`></script>
1011
<meta charset="utf-8" />
1112
<meta name="viewport" content="width=device-width, initial-scale=1" />
1213

src/scripts/mini-coi.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
2+
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
3+
(({ document: d, navigator: { serviceWorker: s } }) => {
4+
if (d) {
5+
const { currentScript: c } = d;
6+
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
7+
r.addEventListener('updatefound', () => location.reload());
8+
if (r.active && !s.controller) location.reload();
9+
});
10+
}
11+
else {
12+
addEventListener('install', () => skipWaiting());
13+
addEventListener('activate', e => e.waitUntil(clients.claim()));
14+
addEventListener('fetch', e => {
15+
const { request: r } = e;
16+
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
17+
e.respondWith(fetch(r).then(r => {
18+
const { body, status, statusText } = r;
19+
if (!status || status > 399) return r;
20+
const h = new Headers(r.headers);
21+
h.set('Cross-Origin-Opener-Policy', 'same-origin');
22+
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
23+
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
24+
return new Response(status == 204 ? null : body, { status, statusText, headers: h });
25+
}));
26+
});
27+
}
28+
})(self);

0 commit comments

Comments
 (0)