Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
XHR vs fetch - wolf.bet
(version: 0)
Comparing performance of:
xhr vs fetch
Created:
5 years ago
by:
Guest
Jump to the latest result
Tests:
xhr
const xhr = new XMLHttpRequest(); xhr.open('GET', 'https://wolf.bet/api/v1/site/stats'); xhr.onload = () => console.log(JSON.parse(xhr.responseText)); xhr.send();
fetch
fetch('https://wolf.bet/api/v1/site/stats').then(response => response.json()).then(console.log)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
xhr
fetch
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the explanation of the benchmark. **What is tested:** The benchmark compares two approaches to making HTTP requests in JavaScript: XHR (XMLHttpRequest) and fetch. **Options compared:** 1. **XHR (XMLHttpRequest):** * Pros: + Widely supported by older browsers. + Allows for more control over the request, such as setting headers, query parameters, and custom methods. * Cons: + Can be slower and less efficient than fetch due to its synchronous nature. + Requires manual handling of event listeners (e.g., onload). 2. **Fetch:** * Pros: + More modern and efficient, as it's designed for asynchronous requests. + Simplifies the request process with a more intuitive API. * Cons: + Less widely supported by older browsers (though most modern ones do support it). + May require additional setup or polyfills for older browsers. **Other considerations:** Both XHR and fetch can be used to make HTTP requests, but they have different use cases. XHR is often used when you need more control over the request, while fetch is preferred when simplicity and efficiency are key. **Library usage:** There is no library explicitly mentioned in the benchmark definition or individual test cases. However, the `fetch` API relies on the browser's built-in support for HTTP requests. **Special JS feature/syntax:** The benchmark uses modern JavaScript features such as arrow functions (`=>`) and template literals (backticks `` ` ``). **Alternatives:** If you're looking for alternatives to XHR or fetch, consider: 1. **Axios:** A popular library that provides a promise-based HTTP client with features like automatic JSON parsing and caching. 2. **jQuery.ajax():** A part of the jQuery library, which provides a simple and intuitive way to make HTTP requests. For more control over the request, you can also use native browser APIs like `XMLHttpRequest` or `fetch`, as used in the benchmark. I hope this explanation helps!
Related benchmarks:
Native XHR vs Fetch (async/await - try/catch)
XHR vs fetch - stake.com
xhr vs fetch send
XHR vs fetch without JSON parsing
Comments
Confirm delete:
Do you really want to delete benchmark?