Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to import only Ajax method from jQuery with Webpack?

I'm working with Webpack and am trying to figure out if it is possible to only import jQuery's Ajax functionality using named module imports or some other method.

After I npm install jquery --save

If I try to import only deferred, it appears successful:

import { Deferred} from 'jquery'; // returns the $.deferred method

but

import { Ajax } from 'jquery'; // returns undefined

Is there a named export for Deferred but not Ajax?

Thanks for any help. I'm open to any npm wizardry but don't want to use bower. I haven't needed it yet and would rather just import the whole jQuery library using NPM than bring in all that for a single module.

like image 646
Dan Hedgecock Avatar asked Jul 18 '15 21:07

Dan Hedgecock


People also ask

Can AJAX be used with jQuery?

jQuery provides several methods for AJAX functionality. With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!

Is jQuery tree Shakeable?

Be careful with libraries When you can, use tree-shakeable versions of libraries. If you're importing a big bundle of minified code from a library, like jquery. min. js , chances are that bundle will not be tree-shakeable.

Is Ajax better than jQuery?

While JQuery is a library for better client-side web page development, AJAX is a technique of doing XMLHttpRequest to the server from the web page and sending/retrieving data used on a web page. AJAX can change data without reloading the web page. In other words, it implements partial server requests.

Is Ajax better than other client-side technology?

Ajax is a set of web development techniques using many web technologies on the client-side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.


1 Answers

It looks like you can just require certain features. This blog post shows you how.

The good news is, as of jQuery 2.1, jQuery uses AMD to organize its dependencies internally. This means you can use AMD to load individual pieces of jQuery, and not the whole library.

Bower is super simple - its nearly the same as NPM but for browser stuff instead of server stuff. And you see it all over the place, I'm sure you can get some functionality out of it. You just use the command line to install your stuff instead of downloading and linking.

I would go for native XHR stuff. Its simpler than people make it out to be. Check out this link for some comparison between jQuery and native ajax.

jQuery is very handy, but I feel like it should be the alternative to doing things native, not the other way around.

like image 79
APassanisi Avatar answered Sep 30 '22 04:09

APassanisi