Domik942,
<!DOCTYPE html>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<script>
var testHtml = '<head><title>second page</title></head><body><p>test script</p>' +
'<script src="jquery.min.js"></scr'+'ipt>' +
'<script>alert("Hello 1");' +
'' +
'$(document).ready(function(){\n' +
' alert(jQuery.fn.jquery);\n' +
'});</scr'+'ipt>' +
'<div>the 7 tag</div><div>the 8 tag</div><div>the 9 tag</div></body>';
var parser = new DOMParser();
var doc = parser.parseFromString(testHtml, 'text/html');
var htmlOld = document.querySelector('html');
var htmlNew = doc.querySelector('html');
document.replaceChild(htmlNew, htmlOld);
var script = document.createElement('script');
document.querySelector('head').appendChild(script);
script.onload = ()=>
document.querySelectorAll('script').forEach(el => {
var s = document.createElement('script');
if(el.text){s.text = el.text; el.parentNode.replaceChild(s, el)}
});
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js';
</script>
</body>
</html>