Last active
August 29, 2015 13:56
-
-
Save jodosha/9269521 to your computer and use it in GitHub Desktop.
Limit endless page loading, by wrapping long running functions invocation in a setTimeout. Run with `bash server.sh`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script>window.PROFILER||(PROFILER={});PROFILER.data={start:(new Date).getTime()}</script> | |
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> | |
<title>JS Timeout</title> | |
</head> | |
<body> | |
<div id="loaded"></div> | |
<div id="long-running"></div> | |
<script> | |
function longRunning() { | |
var milliseconds = 10000; | |
var date = new Date(); | |
var current = null; | |
do { current = new Date(); } | |
while(current - date < milliseconds); | |
$('#long-running').text('finished'); | |
} | |
</script> | |
<script> | |
if(PROFILER && PROFILER.data){ | |
PROFILER.data['end']=(new Date).getTime(); | |
$(document).ready(function(){PROFILER.data['ready']=(new Date).getTime()}); | |
$(window).load(function(){ | |
PROFILER.data['load']=(new Date).getTime(); | |
$('#loaded').text('loaded in ' + (PROFILER.data['load'] - PROFILER.data['start']).toString() + ' ms'); | |
window.setTimeout(longRunning, 100); | |
}); | |
} | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
ruby -run -e httpd . -p 5000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment