Giter Site home page Giter Site logo

pegasus's Introduction

Pegasus Bower version

Load JSON while still loading other scripts

Before

After (with Pegasus)

Pegasus is a tiny lib (0.2 kB min/gzip) that lets you load JSON data while loading other scripts.

Using this technique, you can reduce the time to display data in single page apps without touching the server.

See also fetchival, a small fetch wrapper.

Install

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

Important please note that pegasus is available on npm under @typicode/pegasus

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 .then() method 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>

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+

License

MIT - Typicode

pegasus's People

Contributors

h0lyalg0rithm avatar jhorneman avatar marcopeg avatar oller avatar simonwaldherr avatar snadrus avatar typicode avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.