Alex Rivera | Logout

jQuery vs Standard Backend Programming

Asked 2009-06-15T21:21:41.283
10

I'm curious to know people's preferences...

I've recently gone head-first into jQuery and I am loving it. However, I'm finding that I'm replacing a lot of (somewhat trivial) backend (tech: ASP.NET) functions with tiny jQuery functions. For instance, rather than assign a navigation button as a back-end control and change its class when its page is landed on (ie, highlight the "about" button when on the about us page), I simply parsed the URL and added a class to the button:

var pathname = window.location.pathname;
if (pathname == "/about/") {
    $("#nav-about").addClass("selected");
}

Solutions like these seem rather simple (maybe too simple), but I am always wary to rely too heavily on JavaScript. Does anyone else do similar things to this, and if so, how do you maintain code like this? How do you know where to strike the balance between good ol' trusty server code that works every time and fast, fancy, shiny jQuery that works pretty much every time, except when the user may have JavaScript turned off?

EDIT

I'm not really speaking of this particular instance... I'm talking about little enhancements like this. What is the line you draw when it comes to jQuery enhancements or just do it on the server? Thanks :)

Edit
Report

1 Answer

4

The problem with jQuery is that it fires on document ready. Not a big deal early on, but if you have a heavy page, none of this highlighting stuff is gonna appear until the rest of the page is done loading. This means you could see a "pop", as all the jQuery enhancements fire off.

Better just to do this kinda stuff server side (especially when .NET has the Sitemap already built for you)

answered 2009-06-15T21:37:14.647

Your Answer