Single post
Do I need jQuery?
Having recently made an update to my respond theme for wordpress, I wanted to implement a mobile-targeted menu, taking into account that hover doesn’t work on smartphones and tablets.
The two main options are an always-open menu or something triggered with javascript, whether that be a select field, a dropdown or a slider. Adopting a method of progressive enhancement, I load the page with the menu open and if javascript is enable then we can hide it and add an onClick() to a menu-toggle.
…But do we need to use jQuery for one onClick() event? Although the ~30kb load jQuery adds might not be that big a deal, especially if you have any pictures, it does mean an extra uri to fetch and wait for and the main reason for this is mobile which won’t necessarily have a fast or unlimited data connection.
It turns out I’m not the only one wondering this: http://youmightnotneedjquery.com/
The javascript to implement this is dead easy so I opted to add it to the page via a script tag in the footer. You can get the updated theme from www.a2wd.com/dl/respond.zip, and see this post for installation instructions.
Do I need jQuery?… Probably not.