This repository was archived by the owner on Apr 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathhead.html
More file actions
75 lines (69 loc) · 3.36 KB
/
head.html
File metadata and controls
75 lines (69 loc) · 3.36 KB
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
68
69
70
71
72
73
74
75
<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 (!/^[a-zA-Z0-9_-]+$/.test(branch)) throw new Error('Invalid branch name.');
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 (!/^[a-zA-Z0-9_-]+$/.test(branch)) throw new Error('Invalid branch name.');
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.extractLocalePrefix = (pathname = window.location.pathname) => {
const segments = pathname.split('/').filter(Boolean);
if (!segments[0] || segments[0] === 'acrobat') {
return '';
}
return `/${segments[0]}`;
}
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;
}
const miloLibs = setLibs('/libs');
const unityLibs = getUnityLibs();
const localePrefix = extractLocalePrefix();
const preloads = document.querySelector('meta[name="preloads"]')?.content?.split(',').map(x => x.trim().replace('$MILOLIBS', miloLibs).replace('$UNITYLIBS', unityLibs).replace('$LOCALEPREFIX', localePrefix)) || [];
preloads.forEach((link) => {
if (link.endsWith('.js')) {
loadLink(link, { as: 'script', rel: 'preload', crossorigin: 'anonymous' });
} else if (link.endsWith('.css')) {
loadLink(link, { as: 'style', rel: 'preload' });
} else if (/\.(json|html|svg)$/.test(link)) {
loadLink(link, { as: 'fetch', rel: 'preload', crossorigin: 'anonymous' });
} else if (/\.(png|jpg|jpeg|gif|webp)$/.test(link)) {
loadLink(link, { as: 'image', rel: 'preload', fetchpriority: 'high' });
}
});
</script>