Skip to content

Glassback/pegasus-1

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pegasus Bower version

Load data while still loading other scripts

With Pegasus, you can do this

Instead of this

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.

Backbone user? See backbone-pegasus.

Install

$ bower install pegasus
$ npm install typicode/pegasus # For browserify

Demo

http://typicode.github.io/pegasus

Benchmark

Average time to display data on the demo site.

jQuery only jQuery + Pegasus
EDGE 3000 ms 2100 ms
3G 860 ms 640 ms
DSL 270 ms 230 ms

Note: jQuery is used for illustration only, you can use Pegasus with any other Javascript library.

Usage example

<!-- Load (or embed) Pegasus before loading any other script -->
<script src="pegasus.min.js"></script>

<!-- Make your request(s) -->
<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: To save a network call, you can also directly embed pegasus.min.js code in your html file(it's smaller than the Google analytics tracking code).

Support

All modern browsers and IE8+

About

Load data while still loading other scripts and display data faster in jQuery, Backbone, React, Angular, ... apps

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • HTML 65.3%
  • JavaScript 34.7%