Well, there is an easy way out.
Create a file in the root directory of your github pages repository named 404.html
.
Contents of that file should be:
<!DOCTYPE html>
<html lang="en" id="htmlbody">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Loading...</title>
</head>
<body>
<script>
var doc = document.getElementById('htmlbody');
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {
doc.innerHTML = this.responseText;
doc.removeAttribute("id");
}
if (this.status == 404) doc.innerHTML = "Page not found.";
}
}
xhttp.open("GET", "index.html", true);
xhttp.send();
</script>
</body>
</html>
Basically, that script just uses Javascript to perform an XHR on index.html and make the content the document.
I was reluctant to use document.body
because I'm thinking of updating the whole document, but if it doesn't work, change doc variable to document.body
.
Not sure if this works, so I'll really appreciate feedback.
Remember to use the same domain for the index.html else CORS will kick in.