// the find
typicode/pegasus
Load JSON while still loading other scripts
Pegasus is a small XHR wrapper meant to be pasted into a page's head before other scripts, so a JSON request starts while the app's JavaScript is still downloading. It is aimed at static sites that fetch a data file on load and want that fetch to begin as early as possible. Last pushed in October 2017.
- The inline-first install fits the problem. The script is the first thing on the page, so the request is issued before the app bundle's download starts, and the library adds no extra round trip.
- The API is one function that returns a thenable, plus a global pegasus.timeout. There is little to configure, and it does not depend on React, Vue, or jQuery.
- The repo ships separate AMD, CommonJS, and plain builds from src/, so it can drop into older module setups without a bundler.
- Dormant since 2017. It targets IE9+ and was written for the browsers and bundlers of that time. Adopting it means owning it.
- The trick is mostly available without a library now. A link rel=preload for the JSON file starts the download just as early with no script at all, and the page can read the response with fetch().
- The benchmark is one demo site with no stated method or sample size, and the visible tree has no test directory, so the table cannot be reproduced. The EDGE, 3G, and DSL profiles also predate most of today's network conditions.
- The recommended embedded install copies the whole library into every page, with no version pinning or update path, so fixes never reach sites that pasted it once. Error callbacks receive (data, xhr) rather than an Error, which does not line up with fetch-based code.