views:

84

answers:

2
+1  Q: 

Thin down jQuery

Hi, I have been optimizing my website but the one problem that stands in my way is all the jQuery functions that I do not use. The only ones that I use are for a smooth page scroller. It just seems like such a waste of download time.

My question is: Is there any script or program that will remove the jQuery code that I do not need and leave the 1 or 2 functions that I do need.

+2  A: 

Just reference the library from Google, chances are it will already be cached on the client...

<script type="text/javascript"
        src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"&gt;
</script>

This will also save you bandwidth. StackOverflow and many other sites do this.

Josh Stodola
Plus, jquery really is pretty tiny which served up with gzip...not worth worrying about
Michael Haren
But wait! If Google's servers go down, ... oh, right.
Billy ONeal
@Billy - no worries, skynet is here to stay.
Sky Sanders
The problem with relying on caching is that many browsers invalidate cache on some requests much more than is desired or expected. Even with all headers set correctly to induce caching, most browsers will ignore caches for even a soft reload, or where a page hasn't finished loading (eg stalled) and the user initiates a subsequent request to the same resource.
eyelidlessness
+4  A: 

There's no way to do this, especially since it's not that simple. For example .fadeIn() is one method, but it calls the whole animation section of jQuery to fade the element, but that's after your selector has accessed the traversal section including the Sizzle selector engine...that's how most frameworks are, it'd be very tricky to remove pieces because of so many dependencies inside the framework itself.

That being said, if you're delivering jQuery correctly, it's minified and gzipped, and you're only sending about 24kb to the client which they cache so it's just sent once, not every page load. Also, they may have already cached it from another site, the more people who point their site to the same CDN (the page you're viewing does) the more likely this is to happen.

Google has a CDN, details here, for example from there you can grab jQuery, or jQuery UI:

Also, Microsoft has a CDN, details here, you can fran jQuery and the validation library from it:

Note: these are the current versions as of the time of this answer, don't use these explicit links if you're finding this later, there may be more recent versions available.

Nick Craver
Thanks, I get it now.
Taylor Satula