views:

61

answers:

5

I've recently inherited the maintenance of a big, ugly codebase for a production website. Poke your eyes out ugly. And though it's big, it's mostly PHP code, it doesn't have much JS, besides a few "ajaxy" things in the UI.

Our main current problem is that the site is just too heavy. Homepage weighs in at 1.6 Mb currently, so I'm trying to clean some stuff out.

One of the main wasters is that every single page includes the jQuery UI library, but I don't think it's used at all. It's definitely not being used in the homepage and in most pages, so I want to only include the where necessary.

I'm not really experienced with jQuery, i'm more of a Prototype guy, so I'm wondering. Is there anything I could search for that'd let me know where jQuery UI is being used?
What i'm looking for is "common strings", component names, etc

For example, if this was scriptaculous, i'd look for things like "Draggable", "Effect", etc. Any suggestions for jQuery UI?

(Of course, if you can think of a more robust way of removing the tag from pages that don't use it without breaking everything, I'd love to hear about it)

Thanks!! Daniel

A: 

The library really should account for only 19k of the page size.

But you could search for $(' or $. as most, if not all, jquery calls begin with $.

griegs
or search for jQuery( if the codebase uses that instead of $(' to avoid any possible naming conflicts.
Chad
@Chad, not sure that's what was asked. I think he wants to find where jQuery was being used. if the lib is included at the master page level then you'll only find "jQuery" there. need to search for specific references and $ is a fairly good one.
griegs
@griegs - I don't think you guys read the question :) He wants to remove **jQuery UI**, not jQuery core.
Nick Craver
@Nick, yeah fair call. Still there must be some common theme to calling a jQuery UI method.
griegs
@griegs -There's a convention, I just added a more complete answer for this...but I don't think it's the appropriate way to address the OPs speed issue anyway, tried to include some other tips around that.
Nick Craver
+1 @Nick. I think your right. I suspect that jQuery UI might not be the issue. w/out seeing the site i'd be looking at images as a likely factor in the page size. then i'd look at the javascript.
griegs
@griegs - take a look at the jQuery.noConflict call. Since he has a "big, ugly codebase" I thought that there might be multiple JS libraries and that might mean that whoever coded it originally used the noConflict option. If that is the case, he'll want to search for jQuery( instead of $(In any case, I did - accidentally - ignore that he was asking about the UI library.
Chad
@griegs: Images account for 1Mb. Now they've been severely recompressed and that went down a lot. Scripts account for 600kb. That is ridiculous to me, so I'm working on that too.
Daniel Magliola
A: 

I'd suggest doing a search for $(document).ready or trying to figure out the equivalent the codebase uses to check if the DOM is ready for jquery interaction. Because the UI additions require the DOM all the calls for them are going to be within those functions - you can see where they occur and you can check in them for any of common interactions or widgets

Steerpike
A site may have no references to `$(document).ready`, or `jQuery(document)`, or `something(document)`, or `$(function() {` with no `document`, etc...there are many shortcuts, none of which are jQuery UI specific. He wants to remove jQuery UI, not jQuery :)
Nick Craver
+4  A: 

jQuery UI has a standard naming convention, you can view a full list of widgets/effects here. Comparing to that list you're looking for the corresponding methods mostly:

However, and this is a big however, if your main goal is to reduce page payload size, this should have no effect. Your users shouldn't be downloading this every page load, it should be cached on the client as determined by cache headers, additionally your scripts should be minified (already provided version when you download it) and delivered gzipped.

Also if it's an option, I'd consider using a CDN for both jQuery and jQuery UI, and the stylesheets as well, if you're using one of the default themes.

Nick Craver
Nick, thanks for your answer. My main problem right now is that the first time you hit the website, you get a 188kb file (it's minified already, not gzipped, i'm working on that too). As for Google's AJAX hosting, i've tried that too, but this is a server in Argentina for an Argentinean audience. Believe it or not (I barely can), the JS files loads faster from our server than Google's, when we're not overloaded. I will probably still move it to the bottom and ask for it from Google, but if I can remove it altogether, it's much better. Thank you!
Daniel Magliola
@Daniel - Something to keep in mind is that google's geographically balanced as well, you need to test from a computer in the region rather than remotely, as you're loading from a different CDN node. As more people link to google's CDN, there's also a chance the user *already* cached the file :)
Nick Craver
I'm testing from Argentina :-) I also know about the "people can have it cached already" effect, but I'm not really sure how much that has happened already. Do you have any figures as to how widespread this use is? That said, I'd still prefer to eliminate a useless (and heavy) file even if it's coming from someone else's fast server.
Daniel Magliola
+1  A: 

My advice would be to look at the jQuery UI demo page - http://jqueryui.com/demos/ - and look at each demo and search for the main one or two keywords from each demo, like you would probably do for Scriptaculous. Good luck.

Chad
A: 

Remove the reference, and see where it breaks.

Andrew Lewis
The problem is that the site is big enough that I probably won't notice what broke.
Daniel Magliola