Skip to content

Instantly share code, notes, and snippets.

@colinmollenhour
Last active August 29, 2015 13:56
Show Gist options
  • Save colinmollenhour/9282572 to your computer and use it in GitHub Desktop.
Save colinmollenhour/9282572 to your computer and use it in GitHub Desktop.
Test browser performance of using 100 inline script tags with domReadyQueue vs 1 inline script tag.
<?php /* http://screencast.com/t/rFhmw1S2zsh */ ?>
<!DOCTYPE html>
<html>
<head><title>Script Block Test</title></head>
<body>
<?php if (isset($_GET['mode']) && $_GET['mode'] == 'inline'): ?>
<script type="text/javascript">
var domReadyQueue = [];
</script>
<?php for($i = 0; $i < 100; $i++): ?>
<h4><?php echo $i ?></h4>
<script type="text/javascript">
domReadyQueue.push(function(){ });
</script>
<?php endfor ?>
<script type="text/javascript">
while(domReadyQueue.length) {
(domReadyQueue.shift())();
}
</script>
<?php else: ?>
<?php for($i = 0; $i < 100; $i++): ?>
<h4><?php echo $i ?></h4>
<?php endfor ?>
<script type="text/javascript">
(function(){ })();
</script>
<?php endif ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment