Skip to content
Load JSON while still loading other scripts
Branch: master
Clone or download
Latest commit 55ba7df Oct 4, 2016
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist bump Oct 4, 2016
example bump Oct 4, 2016
src Fix small error (#26) Oct 4, 2016
.gitattributes Create .gitattributes Mar 29, 2015
.gitignore update Aug 28, 2016
LICENSE Replace with (#25) Sep 5, 2016
bower.json bump Oct 4, 2016
gruntfile.js Enhance AMD encapsulation, thanks to @lpil Apr 23, 2015


Pegasus is a tiny lib that lets you load JSON data while loading other scripts.

If you have a static website, using this technique, you can reduce the time to display data. Works with any JS lib (React, Vue, jQuery, ...).


JSON (yellow bar) is downloaded several milliseconds after the JS library (orange bar).

After (with Pegasus)

JSON (yellow bar) and the JS library (orange bar) are downloaded at the same time.


Embedded (recommended)

To save a network call, it's recommended to simply paste the following code pegasus.min.js in your HTML page before other scripts.



$ npm install @typicode/pegasus

Please note that pegasus is available on npm under @typicode/pegasus



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) -->
  var request = pegasus('');

<!-- Load your app lib(s) -->
<script src="lib.js"></script>

<!-- Use .then() method to retrieve data in your app -->
    // success handler
    function(data, xhr) {
      // do something useful like
    // error handler (optional)
    function(data, xhr) {
      console.error(data, xhr.status)

Optionally, you can set a timeout using pegasus.timeout = milliseconds


All modern browsers and IE9+


MIT - Typicode

You can’t perform that action at this time.