Skip to content

Instantly share code, notes, and snippets.

@am
Last active September 14, 2017 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save am/b7c7c762e9064dc9c7fc93e13eb8c0a9 to your computer and use it in GitHub Desktop.
Save am/b7c7c762e9064dc9c7fc93e13eb8c0a9 to your computer and use it in GitHub Desktop.
Load unload iframe - performance / memory
<html>
<head></head>
<body>
<p>Loaded Content</p>
<script>
(function(){
var i, el = null,
x = [];
for (i = 0; i < 10000; i++) {
el = document.createElement('div');
el.innerHTML = 'node ' + i;
document.body.appendChild(el);
}
x.push(new Array(1000000).join('x'));
})()
</script>
</body>
</html>
<html>
<head></head>
<body>
<button onclick="loadGame()">Load</button>
<button onclick="unloadGame()">Unload</button>
<div class="loader"></div>
<script>
var loadGame, unloadGame;
loadGame = function() {
var iframe = document.createElement('iframe');
iframe.className = 'loader--iframe';
iframe.src = 'child.html';
document.querySelector('.loader').appendChild(iframe);
};
unloadGame = function() {
document.querySelector('.loader')
.removeChild(document.querySelector('.loader--iframe'));
};
</script>
</body>
</html>
#!/bin/bash
python -m SimpleHTTPServer 5000
@am
Copy link
Author

am commented Sep 14, 2017

Clone and run with:

 bash run.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment