Download
User Rating: 0/5 ( 0 votes)
Pegasus - Load data while still loading other scripts and display data faster in jQuery, Backbone, Angular, ... apps
With Pegasus, you can do this
![](https://camo.githubusercontent.com/de855556ba126e08f9482df4d3bf61f5bbe51d7a/687474703a2f2f692e696d6775722e636f6d2f38735642746e422e706e67)
Instead of this
![](https://camo.githubusercontent.com/ffde9db5d9fe2b02a65dc57e7b13d30b30d298b9/687474703a2f2f692e696d6775722e636f6d2f766573347549662e706e67)
Pegasus is a tiny lib (0.2 kB min/gzip) that lets you load data while loading other scripts.
Using this technique, you can reduce the time to display data in single page apps without touching the server.
Source: github.com
<!-- Load (or embed) Pegasus and start request(s) before loading any other script -->
<script src="pegasus.min.js"></script>
<!-- Request will start as soon as Pegasus is loaded -->
<script>
var request = pegasus('http://api.example.com');
</script>
<!-- Load your app lib(s) -->
<script src="jquery.js"></script>
<!-- Use the request promise to retrieve data in your app -->
<script>
request.then(
// success handler
function(data, xhr) {
// do something useful like
$('#data').text(JSON.stringify(data));
},
// error handler (optional)
function(data, xhr) {
console.error(data, xhr.status)
}
);
</script>
Note: The same method can be applied with any other JavaScript library (Backbone, AngularJS, ...).
Tip: You can also directly embed pegasus.min.js code in your html file to save a network call (it's smaller than the Google analytics tracking code).