How to avoid common SPA pitfalls when using third-party plugins
blog.isleofcode.com
blog.isleofcode.com
1. understand the language you're using (this would solve the `bind` examples); and
2. learn how to use your libraries properly.
Otherwise, the "don't use $TOOL, because misuse can cause $BAD_THINGS" line of thinking is nearly limitless in its application (jQuery, cars, circular saws, ...).
I whole heartedly agree, which is why with each point I made I did more than just list what was bad, but how to do better, even with jQuery. The real reason not to use jQuery isn't because jQuery is bad, it is because as a tool it / it's ecosystem is poorly prepared for dynamic html, so if you are going to use it, you need to know the limitations and challenges it brings.
For example:
"To be fair, this is no different than cacheing an element or array of elements on your own, and forgetting to de-reference it later when you are done"
or the examples about attaching/detaching event listeners where the hypothetical developer is gathering elements by the equivalent of document.getElementsByClassName. If a developer is going to make that kind of mistake, then that's an error that's going to occur regardless of the framework.
There are certainly reasons to not use jquery in some cases, but this article seems a bit too much like "Do good development, don't do bad development". Drop jquery from the body of the content and the title, and the lesson will still be the same.
Honestly it's a library. Use it, don't use it, replace it, it honestly isn't worth a million identical arguments. People like to use JQuery as a microcosm for bad javascript practices but guess what JQuery didn't make you do it! It's just a library.
There is no real reason to avoid JQuery. Sure you should, as a good developer, explore alternative solutions for different problem sets. Maybe those alternatives become the standard for your team, maybe they don't. But unless you made a meaningful discovery that can add to the conversation, you don't need to make another blog post about it. Ugh.
But many of these complaints have nothing to do with misuse and everything to do with either a lack of awareness about selector consequences, or a decade of built up code debt in the jQuery plugin ecosystem.
All of these examples are true for all JS frameworks, even non-SPA frameworks. Dynamic DOM is a problem for code that wasn't designed to clean up.
There is a real reason to avoid jQuery, that reason is that you want your app to work well. Blindly reaching for a tool from the static age will bite you.
> But unless you made a meaningful discovery that can add to the conversation, you don't need to make another blog post about it. Ugh.
Guessing this is yours ;)
I just think we have to be careful whenever we say "this is bad, do this instead" because people will often inherently believe you and pass it on.
I don't think this applies here. Personally, I learned something from two of his examples, bookmarked the page, and will refactor accordingly. I'll hazard a guess that a few others are in the same boat -- by that standard, the article seems pretty meaningful to me.
Things that ought to be fundamental, but which were left unlearned while the web was allowed to be lazy. With static pages, GC concerns weren't very large, because soon enough the user is going to click ahead to a new page and wipe the slate anyway.
I'll take the opportunity now and ask for good resources on JS performance, garbage collection, and profiling. I realize I know the syntax and semantics well (and a framework or two), but not enough about optimization and related stuff (like ServiceWorker).
"Profiling? What are you messing around with those random toys for? We need to make the buttons rounded!"
> "I've read countless blog posts, twitter rants and medium exposés detailing how jQuery isn't necessary, and why you should just write with "native" JavaScript."
Not reasons.
> "There is, however, a very major reason to avoid jQuery, and it has very little to do with features or file-size."
File-size? Ok. But "features" isn't a reason, without fleshing out.
Learn a lot more about jQuery, if you write complex JS applications (like single-page apps) with the help of jQuery.
I feel like SPAs are one of the most abused concepts on the internet right now.
A cloud-based 3D modeling software? Yeah, that definitely needs to be some form of SPA.
Your twitter clone, blogging engine, etc. not only doesn't have to be an SPA, but shouldn't be one because it creates horrendous UX.
You could disable CSS and images and call the result ugly, but I don't think that entitles you to call the website ugly?
https://gds.blog.gov.uk/2013/10/21/how-many-people-are-missi...
If you want to ignore 1% of the internet, you go right ahead.
Sure, in practice many SPAs might be subpar, but then the debate shifts to "are SPAs are difficult to implement correctly," rather than "SPAs for blogging engines (necessarily) creates horrendous UX". There are existence proofs of well-designed SPAs with logically separate pages and excellent UX.
As an aside, someone who pattern matches on "SPA = horrendous UX" might not even notice a well-designed SPA, further entrenching their belief that SPAs are a Bad Idea from a UX perspective!
This page should be titled: "Don't forget to delete unused JavaScript things (nodes, events, etc)".
Ooops, wrong decade
If you are the type of person who likes to paint ideas and approaches in black and white, pointing out only the upsides of the things you like and only the downsides of the things you don't like, then you're going to REALLY hate programming.