<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
var r = new XMLHttpRequest();
r.open("POST", "http://vanilla-js.com/path/to/api", true);
r.onreadystatechange = function () {
if (r.readyState != 4 || r.status != 200) return;
alert("Success: " + r.responseText);
};
r.send("banana=yellow");
$.ajax({
type: 'POST',
url: "http://vanilla-js.com/path/to/api",
data: "banana=yellow",
success: function (data) {
alert("Success: " + data);
},
});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Vanilla JS | |
Jquery |
Test name | Executions per second |
---|---|
Vanilla JS | 9263.6 Ops/sec |
Jquery | 4043.1 Ops/sec |
Overview
MeasureThat.net is a platform that allows users to create and run JavaScript microbenchmarks. The benchmark in question compares the performance of Vanilla JS vs JQuery AJAX.
What is tested?
The provided JSON represents two test cases:
XMLHttpRequest
API to send an AJAX request to a server.$.ajax()
method to send an AJAX request to the same server.Options compared
The two options being compared are:
XMLHttpRequest
API is used for sending AJAX requests.$.ajax()
method is used for sending AJAX requests.Pros and Cons of each approach
Library: JQuery
JQuery is a popular JavaScript library that simplifies DOM manipulation, event handling, and AJAX requests. The $.ajax()
method provides an easy-to-use interface for sending AJAX requests, which can simplify the code compared to using native XMLHttpRequest
.
Special JS feature or syntax
There are no special JavaScript features or syntaxes mentioned in this benchmark.
Other alternatives
If you prefer to use a different library or framework for your AJAX requests, some alternatives include:
Keep in mind that each alternative has its own pros and cons, and the choice ultimately depends on your project's specific requirements and your personal preference.