-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathhead.html
67 lines (62 loc) · 2.97 KB
/
head.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="preconnect" href="https://acrobat.adobe.com" crossorigin>
<script src="/acrobat/scripts/scripts.js" type="module"></script>
<style>body { display: none; }</style>
<link rel="icon" href="data:,">
<script nomodule src="/acrobat/scripts/fallback.js"></script>
<script>
window.setLibs = (prodLibs, location = window.location) => {
const { hostname, search } = location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
const branch = new URLSearchParams(search).get('milolibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return '/libs';
if (branch === 'local') return 'http://localhost:6456/libs';
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--') ? '' : '--milo--adobecom'}.${env}.live/libs`;
};
window.getUnityLibs = (prodLibs = '/unitylibs') => {
const { hostname, search } = window.location;
if (!/\.hlx\.|\.aem\.|local|stage/.test(hostname)) return prodLibs;
const branch = new URLSearchParams(search).get('unitylibs') || 'main';
if (branch === 'main' && hostname === 'www.stage.adobe.com') return prodLibs;
const env = hostname.includes('.hlx.') ? 'hlx' : 'aem';
return `https://${branch}${branch.includes('--')? '' : '--unity--adobecom'}.${env}.live/unitylibs`;
}
window.loadLink = (href, options = {}) => {
const { as, callback, crossorigin, rel, fetchpriority } = options;
let link = document.head.querySelector(`link[href="${href}"]`);
if (!link) {
link = document.createElement('link');
link.setAttribute('rel', rel);
if (as) link.setAttribute('as', as);
if (crossorigin) link.setAttribute('crossorigin', crossorigin);
if (fetchpriority) link.setAttribute('fetchpriority', fetchpriority);
link.setAttribute('href', href);
if (callback) {
link.onload = (e) => callback(e.type);
link.onerror = (e) => callback(e.type);
}
document.head.appendChild(link);
} else if (callback) {
callback('noop');
}
return link;
}
window.loadStyle = (href, callback) => {
return loadLink(href, { rel: 'stylesheet', callback });
}
const miloLibs = setLibs('/libs');
const unityLibs = getUnityLibs();
const preloads = document.querySelector('meta[name="preloads"]')?.content?.split(',').map(x => x.trim().replace('$MILOLIBS', miloLibs).replace('$UNITYLIBS', unityLibs)) || [];
preloads.forEach((link) => {
if (link.endsWith('.js')) {
loadLink(link, { as: 'script', rel: 'preload', crossorigin: 'anonymous' });
} else if (link.endsWith('.css')) {
loadStyle(link);
} else if (link.endsWith('.json') || link.endsWith('.html')) {
loadLink(link, { as: 'fetch', rel: 'preload', crossorigin: 'anonymous' });
} else if (/\.(png|jpg|jpeg|gif|webp|svg)$/.test(link)) {
loadLink(link, { as: 'image', rel: 'preload', fetchpriority: 'high' });
}
});
</script>