<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
$.ajax({
type: 'POST',
url: "http://vanilla-js.com/path/to/api",
data: {'banana': 'yellow'},
success: (data) = {},
});
const sendAjax = (url, data, callback) => {
fetch(url, {
method: 'POST',
body: new URLSearchParams(data),
}).then((response) => {
const contentType = response.headers.get("content-type");
if (contentType && contentType.indexOf("application/json") !== -1) {
return response.json().then(data => {callback(data)});
} else {
return response.text().then(text => {callback(text)});
}
});
}
sendAjax('http://vanilla-js.com/path/to/api', {'banana': 'yellow'}, (data) => {});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
jQuery test case | |
Vanilla JS test case |
Test name | Executions per second |
---|---|
jQuery test case | 9749.3 Ops/sec |
Vanilla JS test case | 14242.0 Ops/sec |
Let's break down the provided JSON data to understand what is being tested and compared.
Benchmark Definition
The benchmark compares the performance of jQuery AJAX wrapper with Fetch API, which is a vanilla JavaScript API for making HTTP requests. The goal is to determine which approach is more efficient in terms of execution time and operations per second (ops/sec).
Options Compared
There are two main options being compared:
Pros and Cons
Library and Purpose
In the provided test cases:
Special JS Feature or Syntax
There is no specific JavaScript feature or syntax being tested or compared in this benchmark. The focus is on comparing two different approaches for making AJAX requests: using a library (jQuery) versus using a vanilla JavaScript API (Fetch).
Other Alternatives
If you're interested in exploring other alternatives, here are a few options:
Keep in mind that the choice of library or API depends on your specific use case, performance requirements, and personal preference.