[ACCEPTED]-Is there a jQuery stand-alone Ajax module?-jquery
Update 2016
You can use this tool to build your own 3 custom jQuery version.
As of jQuery 2.1.1
Full 2 file sized unminified is: 241.55 Kb
Ajax Only minified 1 is: 49.60 Kb
That is a 5x reduction in size.
As Darin already says, it's all or nothing. JQuery's 6 Ajax functions are closely intertwined with 5 the rest of the functionality.
There are 4 a few other, stand-alone Ajax libraries 3 around like Matt Kruse's Ajax toolbox - maybe that helps.
I would 2 consider loading the full jQuery library. If 1 you link to jQuery on a CDN, loading times will be minuscule.
Another option would be to use the built-in 8 fetch
API provided by the browser.
Here is an 7 example snippet:
fetch('http://localhost:3000/users.json', {
method: 'POST',
mode: 'cors',
redirect: 'follow',
body: JSON.stringify({
user: {
firstName: 'john',
lastName: 'doe'
}
}),
headers: new Headers({ 'Content-Type': 'application/json' })
}).then(function() {
/* handle response */
});
This blog post is a great introduction 6 to the API and shows more use cases.
fetch
doesn't 5 have full cross-browser support yet (I think 4 mainly IE and Safari are lacking), but there 3 is polyfill that you can use until that 2 day comes.
fetch
polyfill: https://github.com/github/fetch
Older browsers will 1 also need a Promise
polyfill (one option, another option).
You can view standard javascript alternatives 2 to jQuery at youmightnotneedjquery.com
For example the alternative 1 to $.ajax
post
is:
var request = new XMLHttpRequest();
request.open('POST', '/my/url', true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.send(data);
And the alternative to $.ajax
get
is:
var request = new XMLHttpRequest();
request.open('GET', '/my/url', true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
// Success!
var resp = request.responseText;
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function() {
// There was a connection error of some sort
};
request.send();
I've created a custom build of jQuery 1.7.1 1 here:
AMD user please read this, my answer is for 5 building a single file.
Or just use this 4 library: ded / reqwest (4 KB, min & gzip)
Download 3 source code and run
npn i
Open
/src/jquery.js
and remove any moudle you 2 don't want, but keep"./exports/amd"
,"./exports/global"
define([ "./ajax", "./ajax/xhr", "./ajax/script", "./ajax/jsonp", "./exports/amd", "./exports/global" ], function (jQuery) { "use strict"; return jQuery; });
Run
grunt custom:-sizzle
Goto
/dist
and take 1 your build
Modules in your build now:
- core
- deferred
- ajax
Size:
- just build: 85 KB
- build with min: 26 KB
- build with min & gzip: 10 KB
If you really really want just the Ajax 9 parts of jQuery you can get the code from 8 their repository (https://github.com/jquery/jquery), glancing at it you 7 would want to look at "ajax.js" and 6 "core.js" in the "src" directory. You 5 would then want to compile them together 4 with the closure compiler or something.
But 3 as others stated, it would be a lot easier 2 to just load it from one of the CDNs (jQuery, Google, Microsoft) which 1 most users will have cached anyway.
YES, I just did mine, http://noypi-linux.blogspot.com/2013/05/build-jquery-with-ajax-only.html
you only need these 1 files (resulting minified is about 30Kb):
/d/dev/javascript/jquery/jquery/src/intro.js
/d/dev/javascript/jquery/jquery/src/core.js
/d/dev/javascript/jquery/jquery/src/callbacks.js
/d/dev/javascript/jquery/jquery/src/deferred.js
/d/dev/javascript/jquery/jquery/src/support.js
/d/dev/javascript/jquery/jquery/src/data.js
/d/dev/javascript/jquery/jquery/src/event.js
/d/dev/javascript/jquery/jquery/src/serialize.js
/d/dev/javascript/jquery/jquery/src/ajax.js
/d/dev/javascript/jquery/jquery/src/ajax/xhr.js
/d/dev/javascript/jquery/jquery/src/exports.js
/d/dev/javascript/jquery/jquery/src/outro.js
You can try AJAJ. It's a very tiny(less than 3 1kb gzipped) library to make ajax calls. And 2 its syntax is very similar to jQuery.
For 1 example:
ajaj({
method: "POST",
url: "/path/to/request",
data: {
name: "AJAJ",
version: "1.0.0",
},
success: function (data) {
console.log(data);
},
fail: function (error) {
console.log(error);
},
});
It's all or nothing. Of course jquery is 7 open source and you could extract the part 6 you are interested in in your own library 5 (good luck with this). You may consider 4 using a CDN which will ensure that most 3 users will already have it cached in their 2 browsers so you shouldn't be concerned about 1 size.
There is none out of the box but you can 7 of course cut and paste from the existing 6 file and then minimize it.
If you are just 5 worried about the size of the library serving 4 it from a CDN from Google, MS or jQuery 3 will probably require less data traffic 2 as most browsers already have the files 1 cached.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.