The question is: should I use always jQuery in some large jQuery project? Imagine you’re developing a large scale web application where the JavaScript part of it is supported by jQuery. In my case that was the reality. In fact in every, even very big, project there are “pages” where you don’t need much of JavaScript. Such pages can be the “about”, “info” or whatever static page there is.
Well the question is, should I again include the hole jQuery if I need only to toggle the visiblity on a DIV element? Let’s assume you’ve very long text, cutted in the beggining with the “more” link somewhere after the intro. That’s very common, isn’t it? So by clicking on the “more” you toggle the visibility of the rest of the text. Well of course it’s absurt if I include the entire library just to make this.
The right answer by me is to use pure JavaScript, something like that:
document.getElementId('id').style.display = 'block'
That will do the same job without to block the “fast” in other way page!
What is point of using javascript on single page, if jQuery is going to be loaded by visitor, anyway? (on other pages)
Just hotlink to google code to save bandwith for both your server and visitor.
Well nobody says that jQuery is loaded on every page! And there’s the answer of your question!
best regards,
stoimen
jquery is a toolkit not a manacle – do whatever you want. The only reason I would use it in this case is if I am using ‘slow fades’ or similar effects on other pages and want this to be the same.
The code will be cached locally from other pages, so the only delay would be the time taken to parse the code – negligible on any modern pc.
John
Hi John,
OK if you’d like to use effects it’s better to include the library. However I know that jQuery is, but the question is not what’s the difference between jQuery and JavaScript, this is nonsense, but whether you need all the functionality given by jQuery just for a simple effect.
Another thing I won’t agree is that the code will be cached. If you code a page with the presumption in mind that everything is cached before “that page is loaded” sooner or later you’d know that not everybody’s using cache enabled browser, gzip or whatever good thing that web developers would like to be enabled. It’s not bad if you start developing with optimization in mind.
greetings,
stoimen
My answer is yes.Yes, just go on with JQuery. Although I’m using Mootool in my new project, http://quickmessageapp.com, or whatever javascript framework, *It* will simplify your job.
Just imagine, how big javascript framework and how fast internet connection nowdays? 24-68 KB just a second or two on todays broadband.
Just my two cents 🙂
Second or two? That’s too much for a website it must load the entire site for a second, not only the javascript framework.
Well, at some places it’s good to use Jquery, for example, we are using it for sorting at client side. Now we don’t need to send a request to server and wait for the response.
However, one question, I’ve, where I feel, Jquery shuould be a bit slower. For every event a search has to be made through the entire DOM, to find the places, where the event is registered.
With pure JavaScript this is not the case.
Please correct me if I’m wrong.
I agree! It’s better to use jQuery when the task you want to do is rather difficult and the maintanence of the code will be easier!
If you are using jQuery on the “main” pages of your site/app, then go ahead and include it on all pages since it will be cached in the user’s browser anyway. If you are a public site, then link to Google’s CDN version of jQuery, if not be sure to set a far future expires date.
try with minified versions of jquery and feel free to check how fast it works.
it’s awsome
@amila – believe me I’ve tried 🙂 but here it doesn’t matter how fast it is loaded by the browser (whatever minified or not). However when the browser’s JS engine tries to parse and execute the code than it really matters how “large” it is!
I have not used jquery and am still developing web pages (maybe I’m just outdated) whose major functionality is operational even with javascript turned off.
And example would be an faq that has answers that open and close when the question is clicked. The questions are in the open state but I use javascript to close them all when the page is loaded. If you had javascript turned off then all the answers would be expanded.
I have been writing javascript for approximately 15 years so I’ve gotten pretty good at it. I have my own libraries but I am considering looking into jquery.
I have seen web pages using jquery that are slow and when I view the source it is a huge mess. I suspect that whoever wrote it used nothing but tools and libraries with limited knowledge of how everything works.
If you really want tidy fast pages I don’t think there’s an alternative to knowing what everything does even if you choose tools to make the job easier.
I think jQuery is many times better to use than javascript which is quiet frankly a badly written programming language jQuery can aid a lot of web designers without any solid programming background and that’s one of the reason it is used so widely