Created
June 17, 2014 20:52
-
-
Save mamchenkov/548970e9ba66db8af632 to your computer and use it in GitHub Desktop.
Facebook BigPipe, pagelets, and other parallel loading test
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
<?php | |
/* | |
* If we are being called as Ajax content provider, just print | |
* something out, based on passed parameters. Sleep for more | |
* obvious results. | |
*/ | |
if (!empty($_REQUEST['widget']) && !empty($_REQUEST['id'])) { | |
$config = $_REQUEST['widget'] . '-' . $_REQUEST['id']; | |
switch($config) { | |
case 'text-one': | |
sleep(3); | |
print "<h3>Hello</h3><p>This is text configuration #1.</p>"; | |
break; | |
case 'text-two': | |
sleep(1); | |
print "<h3>Hi</h3><p>This is text configuration #2.</p>"; | |
break; | |
case 'text-three': | |
sleep(5); | |
print "<h3>Yo!</h3><p>This is text configuration #3.</p>"; | |
break; | |
default: | |
print "<h3>Oops</h3><p>This is unknown configuration.</p>"; | |
break; | |
} | |
die(); | |
} | |
?> | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Proof of concept : BigPipe</title> | |
<link href="//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet"> | |
</head> | |
<body> | |
<div class="container"> | |
<div class="row"> | |
<div class="ajax span4" data-widget="text" data-id="one"></div> | |
<div class="ajax span4" data-widget="text" data-id="two"></div> | |
<div class="ajax span4" data-widget="text" data-id="three"></div> | |
</div> | |
</div> | |
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> | |
<script src="//maxcdn.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('.ajax').each(function() { | |
var response; | |
var element; | |
element = this; | |
params = { | |
widget: $(this).data('widget'), | |
id: $(this).data('id') | |
}; | |
$.get('index.php', params, function(response) { | |
$(element).html(response); | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍