0

I'd like to ask a simple question, Should I use javascript or jquery?

For all I know, jquery is difficult for me to learn (the ajax part at least) and I already know javascript and how to do almost everything in javascript. In some functions I have to say that in my website I used jquery mostly because of the fancy animations but only for that. That is as far as I can go with jquery. So will jquery offer me more in performance or not? Should I learn jquery to create the ajax functions or just stick with javascript?

Also I know it wouldn't be ideal but do you believe that using both jquery and javascript (of course for different functions) will be buggy??

Thanks in advance.

EDIT: Of course I know that jQuery is a Javascript framework I'm asking if it will offer something more in performance thanks.

user229044
  • 232,980
  • 40
  • 330
  • 338
viper
  • 539
  • 1
  • 4
  • 16
  • You cannot use jQuery without using javascript. jQuery is an extension of javascript. Your question is like asking "should I use C# or .NET?" – Jamie Treworgy Jul 05 '11 at 18:03
  • @jamietre: It's not an extension. It's just a set of functions – SLaks Jul 05 '11 at 18:04
  • 1
    More like apple or apple pie? – Abdullah Jibaly Jul 05 '11 at 18:04
  • 1
    @Slaks I was deliberately inaccurate to make the point that you can't have the latter without the former. Though I might argue that any function could be described as an extension of the code used to write it, especially so in a langue like javascript where functions are first class objects. – Jamie Treworgy Jul 05 '11 at 18:07
  • 9
    "Performance" is the absolute last thing you should consider when thinking of adopting jQuery for AJAX stuff. **It doesn't matter**, stop dwelling on it. The network transmission is going to be the slowest part by orders of magnitude. There are times when performance matters. This is not one of them. – user229044 Jul 05 '11 at 18:08

10 Answers10

6

jQuery is Javascript.

It's just a set of Javascript functions that many people find very convenient.
jQuery.ajax in particular is much easier to use than the native XMLHTTPRequest.

There is nothing wrong with calling functions that aren't defined by jQuery.

Community
  • 1
  • 1
SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I didn't say that there is something wrong. I simply asked if it would offer me something more in performance or something less. Which one is better in terms of performance? – viper Jul 05 '11 at 18:05
  • 2
    @Simos: Your question does not make sense. – SLaks Jul 05 '11 at 18:05
  • 3
    Don't worry about performance unless you're dealing with astronomical amounts of data. – SLaks Jul 05 '11 at 18:06
  • Ok here is what I'm saying. I know php and I know also smarty and I've noticed that smarty sometimes causes the load to go up and the page to generate with a small delay. I know people that use cakephp and said that it's actually faster. That is the performance I'm talking about. Will jquery other than writing more easier and cleaner code benefit in somewhere else? – viper Jul 05 '11 at 18:09
  • Nice answer :) If it's true I'd take this as an answer :) – viper Jul 05 '11 at 18:09
  • 3
    jQuery is slightly slower than raw DOM access. **Don't worry about it**; you will have bigger performance issues (the network). – SLaks Jul 05 '11 at 18:10
  • 2
    @Simos Mikelatos: Performance differences in using a framework such as jQuery should be minimal and not even measurable compared to the difference in the expressiveness and supportability of the code. If you run into a particular situation where you find that a jQuery implementation is slower than a native JavaScript implementation, you can swap out the former for the latter. But there's no reason to avoid using jQuery based on the possibility of such concerns. – David Jul 05 '11 at 18:10
  • 1
    +1 Slaks. The difference in perf. between your own raw code for most common things, vs. using a framework, will probably not be more than an order of 2. The range of computing power running your web site will be an order of 100. It's unlikely to make or break anything. Code first - optimize bottlenecks (if they even exist or matter) later. – Jamie Treworgy Jul 05 '11 at 18:13
  • 1
    @Simos "Will jQuery other than writing more easier and cleaner code benefit in somewhere else?" You're asking the completely wrong questions. Get this fundamental fact into your head: **Performance does not matter**. Producing clean, secure and maintainable code should be your first consideration. These are the only benefits you should need to see in order to realize that yes, you very obviously should adopt jQuery or some other JavaScript library. – user229044 Jul 05 '11 at 18:16
5

jQuery is JavaScript. It's only a framework. So you are totally safe to use both.

Answering your updated question on how jQuery frameworks offer you more than dealing with plain JavaScript:

  • Write less code and do more
  • Cross-browser compatibility out-of-the box
  • A lot of really good plugins available

You should not worry about performance. jQuery gives you so much more.

Martin Buberl
  • 45,844
  • 25
  • 100
  • 144
4

jQuery is a JavaScript library, so in order to use jQuery you have to be using JavaScript.

That being said, you're free to use both. Use plain JavaScript where you want, use the jQuery library for code which is more clearly expressed in jQuery.

David
  • 208,112
  • 36
  • 198
  • 279
2

jQuery IS Javascript actually.

But for question, just use both, because jQuery is faster for some stuff, but it is limited. It is only Javascript library.

Jaanus
  • 16,161
  • 49
  • 147
  • 202
2

jQuery is javascript.

That said, if you already are using jQuery in your website, I'd recommend making use of its ajax support. It really is much nicer than attempting to write your own cross-browser implementation.

Mark
  • 768
  • 5
  • 12
  • The cross browser implementation is just a 10 line code nothing that difficult :/ – viper Jul 05 '11 at 18:06
  • 2
    @Simos: jQuery offers much more than just cross-browser hacks. Also, covering all cases requires substantially more than 10 lines. – SLaks Jul 05 '11 at 18:09
  • @meagar I was talking about the ajax part only. – viper Jul 05 '11 at 18:14
  • Now how many lines of code are the cross-browser implementations of *everything* you do in javascript? Probably somewhere around 70K, roughly the size of a framework like jQuery. So you can reinvent hundreds of thousands of programmer/testing hours, or just use something that already exists. – Jamie Treworgy Jul 05 '11 at 18:15
2

A question for you - you say you know javascript very well, so have you created a javascript plug-in? ie. a set of reusable functions that you use throughout your site?

jQuery is just this - nothing more. It is a wrapper around javascript that saves a lot of time and code in certain situations.

BonyT
  • 10,750
  • 5
  • 31
  • 52
2

jQuery does not offer anything over Javascript in terms of performance. It's purpose is to make development easier, better and more productive.

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
2

You can do the same functions that jQuery does with Javascript, because jQuery is made with Javascript code.

jQuery tries to simplify a lot the visual and selection tasks that are more tedious with JS.

Use jQuery and, when you need to be more specific, add JS.

IsaacSF
  • 126
  • 5
1

As others have noted jquery is javascript..

absolutely jquery, in my opinion, animation is not most amazing part. With jquery you can handle the cross-browser javascript code very easily, and i think the ajax part is so much easier and flexible than the pure javascript xmlhttprequest.

James.Xu
  • 8,249
  • 5
  • 25
  • 36
1

Yes, I would definitely go for jQuery. At start it seems to be a bit difficult, but you'll soon find out that jQuery is way easier to use and better in performance.

After all Javascript takes like 20 lines to make an Ajax call. jQuery would just do (for example):

$.ajax({
   type: "POST",
   url: "yourscript.php",
   data: ({ id : retrieved_id,
           firstname : firstname }),
   success: function(data) {
     $('#txt_id').html(data);
   }
});

jQuery will ease up a lot of things for you. I used to be familiar with Javascript too and I was a bit hesitant to start using jQuery, but now I cannot live without it anymore!

Keep in mind though that jQuery IS just like a Javascript library. So you will still be using Javascript.

user229044
  • 232,980
  • 40
  • 330
  • 338
Jules
  • 7,148
  • 6
  • 26
  • 50
  • @meagar Thanks a lot :) Do you have any good book or article to recommend for ajax and jquery? – viper Jul 05 '11 at 18:11
  • @Simos Mikelatos You're welcome. I don't have a book that I use but the JQuery api website is really handy ([link](http://api.jquery.com)) and this one is dedicated for the Ajax calls: [link](http://api.jquery.com/jQuery.ajax/) – Jules Jul 05 '11 at 18:18
  • @Jules jQuery is no better or worse in performance than JavaScript - that is *not* a valid reason to adopt the framework. – user229044 Jul 05 '11 at 18:22