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?
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 :)
On other hand Jquery is a library developed by Jquery project group used for backend web development by using its predefined functions and utility to make application development easier and faster.
jQuery is a lightweight, “write less, do more”, JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your website. jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish and wraps them into methods that you can call with a single line of code.
In a word, yes. Ever since jQuery was introduced in 2006, it's made client-side development so easy when using JavaScript. Fourteen years later, it's now the 2nd most popular web framework out there based on the just-released 2021 Stack Overflow Developers Survey .
Pure JavaScript can be faster for DOM selection/manipulation than jQuery as JavaScript is directly processed by the browser and it curtails the overhead which JQuery actually has. JQuery is also fast with modern browsers and modern computers. JQuery has to be converted into JavaScript to make it run in a browser.
Javascript is an extra layer on top of HTML and CSS. When you're building an accessible website, everything should be available in just the HTML. Both CSS and Javascript should only be used to enhance the user experience.
I would even go as far as to say that for every single page interface or RIA, there should be a multipage alternative.
So, to answer your question, this is definitely something you'd want to code on the server, not the client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With