This repository has been archived by the owner on Jul 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
59 lines (53 loc) · 2.34 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
50
51
52
53
54
55
56
57
58
59
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Dynapage</title>
</head>
<body>
<div hidden="" id="dynapage-config">
<div id="dynapage-html-src" data-method="[HTTP METHOD TO YOUR PAGE]"
data-source="[FILL YOUR HTML PAGE SOURCE HERE]"></div>
<div id="dynapage-js-deps">
<div data-source="[FILL YOUR JAVASCRIPT DEPENDENCY SOURCE 1 HERE]"></div>
<div data-source="[FILL YOUR JAVASCRIPT DEPENDENCY SOURCE 2 HERE]" data-crossorigin="[CORS SETTINGS HERE]"
data-integrity="[HASHES HERE]"></div>
<!-- ... n more -->
</div>
</div>
<div id="dynapage-container">
<!-- Your page content will be filled here. -->
</div>
<script>
const elemConfig = document.getElementById('dynapage-config')
const elemSrc = document.querySelector('#dynapage-config > #dynapage-html-src')
const pageSrc = elemSrc.dataset.source
const pageMeth = elemSrc.dataset.method
const htmlXhr = new XMLHttpRequest()
htmlXhr.addEventListener('load', () => {
if (htmlXhr.status === 200) {
const elemContainer = document.getElementById('dynapage-container')
const elemWrapper = document.createElement('div')
elemWrapper.innerHTML = htmlXhr.responseText
elemContainer.insertAdjacentElement('beforeend', elemWrapper)
const jsDeps = document.querySelectorAll('#dynapage-config > #dynapage-js-deps > div')
for (let idx = 0; idx < jsDeps.length; idx++) {
const dep = jsDeps[idx]
const depDataset = dep.dataset
const elemJs = document.createElement('script')
elemJs.setAttribute('src', depDataset.source)
if (depDataset.hasOwnProperty('crossorigin')) {
elemJs.setAttribute('crossorigin', depDataset.crossorigin)
}
if (depDataset.hasOwnProperty('integrity')) {
elemJs.setAttribute('integrity', depDataset.integrity)
}
elemContainer.insertAdjacentElement('beforeend', elemJs)
}
}
})
htmlXhr.open(pageMeth, pageSrc)
htmlXhr.send()
</script>
</body>
</html>