views:

395

answers:

5

jQuery and similar libraries provide a number of useful APIs for DOM traversal and manipulation. Where your site as high number of repeat visitors, their use is easily justified as caching will offset any bandwidth cost to the end user.

In other cases visitors to the site might always be unique and thus the bandwidth penalty for these libraries can be too severe relative to the benefits for a development team.

Are there any libraries that provide this style of DOM interaction while allowing you to choose the parts relevant to your page.

For example,

jQuery('#myId').addClass('error');

and many other APIs in jQuery can be replicated in a few lines of code, thus avoiding ~50kB of downloads.

So the question is, does a library exist that contains these functions with little dependency on other aspects of the library or will I need to create them myself as necessary?

Are there mechanisms/tools available to break down existing libraries like jQuery into their minimal components?

+4  A: 

As discussed here, if you use google as a host of the libraries, the user probably already has it cached before they ever get to your site.

This page shows you which libraries are supported. Currently:

  • jQuery
  • jQuery UI
  • Prototype
  • script.aculo.us
  • MooTools
  • Dojo
  • SWFObject New!
  • Yahoo! User Interface Library (YUI) New!


I'm all for rolling your own, but be sure you know all the bugs of all the browser versions if you don't use a library.

Not a bad idea, though. It would be nice if you could create a custom version of jQuery. I'd especially like one for iPhone's Mobile Safari and Adobe AIR that stripped out all the non-webkit stuff.

Nosredna
Using the Google hosted version was considered. We can't guarantee a user will have the item cached and a reasonable portion of the user base are not on broadband connections. User experience is paramount.The site is also for secure content so external hosting isn't entirely desirable.I'm not really a fan of rolling my own, it isn't the core competency of the business. Ultimately I'd just like to find a way, or have a tool that allows selection of the desired parts of jQuery etc.
bradhouse
+1 good idea for stripping out non webkit stuff!
alex
I heard that jQuery is working on a mobile version, I assume without all the junk needed to support the funkiest of the desktop browsers.
Nosredna
A: 

Check out Sly. Only 3kB.

RedFilter
That's just a selector engine right? You can't do manipulation with it, I believe. Sizzle, Peppy, and others are similar
Nosredna
That's correct.
RedFilter
Not a bad start, though. With the selector engine out of the way, the manipulation shouldn't be too hard.
Nosredna
+3  A: 

The production version of jQuery is 19k, same as a rather small image. Not a severe bandwidh penalty in my book!

Edit: ..and worth every k, too.

Tor Haugen
Just to be clear, it's 19k *after* gzip (which should be applied to the majority of transfers). The minified version of 1.3.2 is actually 56k. Since most other libraries don't advertise that number, basing comparisons on its gzipped size can lead to confusion.
Dave Ward
+1  A: 

MooTools allows you to download only the pieces you want. So if all you want is enough for JSON AJAX requests, you've got it.

http://mootools.net/core

rpflo
Yeah, thats pretty good. You're at 30k once you pull in element and element style. I guess if you don't pull in much else, that's a decent savings over jQuery.
Nosredna
And of course, gzipping makes from some pretty small files.
rpflo
A: 

Sorry guys I somehow lost the page in which one was asking about JS libraries conflicts solution.

I had the same problem but now I solved it after playing around with some JQuery scripts. I know it is a bit pain in * but lets do it step by step.

First of all let me tell you that in my project I am using two different libraries. I am using Lightwindow and JQuery. I couldn't make both of the libraries function properly BUT I came up with the following script. You have to use this script within each function that is meant to be using the JQuery functions:

//This line says, that dollar sign $ is belongs to the JQuery library.

jQuery(document).ready(function($) { //Your source code goes here.

});

Lets use it in little bit detailed. In my scenario I am having a click button that suppose to call the following function:

        function popups(message, heading, actionlink, linkName) {  

//This is the LINE that tell the rest of the source code //to recognize JQuery functions.

            jQuery(document).ready(function($) {

            // get the screen height and width    
            var maskHeight = $(document).height();    
            var maskWidth = $(window).width();  


            // assign values to the overlay and dialog box  
            $('#dialog-overlay').css({height:maskHeight, width:maskWidth}).show();  
            $('#dialog-box1').show();  


            // display the message  
            $('#dialog-message-row').html(message);  
            $('#dialog-message-heading').html(heading);  
            $('#dialog-message-actionlink').html("<a onclick=function('x') class='button' id='delete'>"+linkName+"</a>");

           });//CLOSE JQuery translator
        }
Sailab Ash Khan Pattan