by random28345 · 11y ago · 0 comments
Not because of selectors, that's (sometimes) easy to do for lots of (basic) selectors. Not because of DOM manipulation, as long as you're willing to sacrifice simplicity and readability, you can build iterative loops to modify a collection of HTML elements.
No, it's the unexpected things that cause me pain. Want to use event handlers on dynamically generated DOM objects? Write your own event bubbling library. Want to create custom events/handlers? Ditto. Promises, .serialize(), .extend(), etc. might all be simple to write your own version, but when you realize you've reimplemented 50% of jQuery to avoid using jQuery, you feel like an idiot. [Source: I do this every 3 years]
Life is too short to not use jQuery.
Life isn't always a hipster website where people can get lunch delivered on their phone or whatever. Things like jQuery are fine.
https://www.npmjs.com/package/browserify
https://www.npmjs.com/package/react
And then use just what modules you need. All the functionality of jQuery has already been ported to various modules.
https://www.npmjs.com/package/extend
Doing the simple, effective thing is just crazy talk, I tell you.
Browserify is not at all complicated.
spend days choosing between a bunch of almost identical micro-libraries for every little thing you need to do
Just search npm and pick the one that is being used the most.
lock yourself into a proprietary framework that will be considered legacy code as soon as next week’s trendy framework arrives
The problems that npm and browserify solve are at the level of builds and package management. You could use any number of trendy frameworks and tools on top of this.
Right. But last week it was RequireJS, not Browserify. Today, as well as NPM, we have Bower and gem and pip and however many other package managers. Last week it was Angular, this week it’s React, and next week maybe it will be Web Components. Last week it was Grunt, this week it’s Gulp, and next week who knows?
The list goes on, but it always seems to be the same basic argument: for some reason, we are told, we suddenly need 73 different tools and templates and scaffolds and packages and boilerplates just to start a simple project. It’s long past time we stopped accepting that kind of rhetoric as if it’s some unquestionable truth. Ultimately web pages are still primarily made of the HTML, CSS and JavaScript that you serve to browsers. Everything else should have to pay its way, and there are always costs in complexity and maintainability when you introduce any external dependency into your project.
Now just to be clear, I am absolutely not saying don’t use good tools. If you are working on a large, complicated project, of course you should be systematic about it and control your dependencies and automate your processes. Even if you’re only working on a small project, low cost tools like jQuery or SASS might more than pull their weight. But it’s important to choose tools that fit the problem and offer a good cost/benefit ratio. Most web projects aren’t large and complicated, and many don’t need elaborate build processes and package management schemes at all. There is no good reason that such projects should give up on a simple, effective tool like jQuery just because you can also solve the same problems now with heavyweight tools like React and Browserify and some combination of NPM-managed packages.
This is basically the algorithm for picking jQuery
And that's fine, if writing a framework per project is something you have time for. But make no mistake -- you're writing a framework.
These are all cool things, but sometimes you want to simply make a web page without setting up node and npm and all that jazz.
Think of it this way... jQuery is like getting a subset of the most common functions you get by using in browserify, but without requiring a build step!
jQuery's imperative DOM manipulation is a horrible way to manage state compared to React.
These tools aren't just "cool things". They were designed to solve really pressing issues related to managing complexity in front-end web applications by eliminating global state in both the DOM or the JS runtime environment. They tend towards a more declarative and functional approach to system design.
A build process that integrates with a versioned package manager is fantastic.
No, absolutely impossible. That would mean I'd have to actually write JavaScript instead of LiveScript and that would be unbearable... ;)
On a more serious note: yes, node is a bit of an overhead. It may be too much for very simple, one-off projects, but it starts making sense as soon as the project becomes even a little bit more complex.
Basically you import everything you need and only what you need. Need extend? No prob: http://microjs.com/#extend - just pick one. And with browserify and npm literally everything you need to do to include a library in your project is a single command, so having to include "that many libraries" is not really a problem.
I'm a huge fan of having many little libraries instead of a few big ones, and JS - both on the backend and frontend - makes this possible to the bigger extent than most other environments.
Real bundling with tools like Browserify is making it more and more feasible to use single-purpose libraries instead of monolithic ones like jQuery.
I agree with all those things. jQuery is the lowest common denominator. It's the best at nothing, bloated with support for Palm Pilot browsers and Safari 1.0, and doesn't have all the cool grunt/gulp/amd/broccoli/cucumber/jsx/fotm neologisms. If I'm building a new, long-term project, I'm going to evaluate all the options, and craft the best possible technology stack for my new app.
But sometimes worse is better. Like a smooth pebble pulled out of a stream, it's taken a long journey and had most of the rough edges rubbed off. It's already in your browser cache from 4 different CDNs. Someone else can pick it up and support it easily. And that's what often makes it the best choice, when you want to avoid bikeshedding over what the hottest new thing is, and just make a webpage.
jQuery may not be the best technology, but it's a sane default.
Thankfully we only support IE9+ where I work, so I grab the latest 2.x version these days.
[0] - http://blog.jquery.com/2013/04/18/jquery-2-0-released/
So ..using jQuery via a CDN, depending on which you use you have a 1 in 119, or 1 in 833 chance of the user having a cached copy. http://www.i-technology.net/2013/11/the-myth-of-cdn.html
more data: http://www.stevesouders.com/blog/2013/03/18/http-archive-jqu...
There are valid reasons to use a CDN (get the scripts closer to the end user, offload the data transfer costs to the CDN provider, etc) but it isn't due to the potential for a cache hit.
That statistics has assumptions on what's the most popular jQuery versions being used. It would make sense if there was real data to support that.