14 ms·
Vanilla-todo: A case study on viable techniques for vanilla web development
- tobr 6y agoThis is nice, patterns over libraries. I would question the choice to use ES5, as it makes it significantly more complicated to handle dependencies between modules in a scalable way. I understand the point of avoiding a build step, but if the code can run in modern clients without it I don’t think it breaks the spirit of the project to use a bundler to support certain older browsers. It’s a lot like using polyfills when needed.
- rablackburn 6y agoAgreed, I originally thought this might be an older project from a couple of years ago because of the ES5. “Vanilla” doesn’t have to mean “supports IE11” in 2020 (before anyone jumps on me, yes, depending on your users you may very well still need to support it, but it’s very clearly on the way out - finally) I love the motivation behind the repo though. The author’s write-up is fantastic and refreshingly reasonable in the dogmatic webdev world. It gives great insight into the places where real value _is_ provided by frameworks and build tools
- morrvs 6y agoThank you very much! This is quite exactly what I'm trying to achieve. Very happy that you like it :)
- brodo 6y agoI did not know how widespread ES5 is nowadays: https://caniuse.com/es6 https://caniuse.com/es6 says 94.69% of users worldwide use a browser that fully supports it.
- morrvs 6y agoOriginal author here - thanks! Yes, ES5 is a huge pain. However, I believe 5% of users (see other comment) are not a joke for many apps. There's always the question of minimum critical APIs required: If you build a 3D or webcam app you can forget ES5 altogether, of course. > It’s a lot like using polyfills when needed. Never thought of it this way, thanks for that! As is state in the conclusion, the study would likely be more convincing with ES6 and build steps. So yeah, ES5 is questionable :)
- jeroenhd 6y agoI very much appreciate proof that we don't need modern frameworks as much as people claim we do. As for ES5 support, would you consider using something like Babel to be close enough to using polyfills to consider them? Transpiling ES6 into ES5 fixes your compatibility issue with ES6 just like I would argue adding a polyfill for WebP images would.
- morrvs 6y agoThanks, although I wouldn't claim it to be "proof" :) and yeah, the choice of ES5 vs. ES6 seems to be a major weakness of the study as others here have said as well. In any case I believe switching the current product to ES6 would make the results even more convincing.
- DarkWiiPlayer 6y agoPartly I agree, 5% of users is a lot. However, this number will only continue to decrease as time goes on, and it also has to be questioned for any specific product whether that number is bigger or smaller on average. Both for the (near?) future when ES6 is near-universal and for projects that have the luxury of just ignoring older browsers even today, it would be nice to have a proof of concept project like this that uses modern ES6 features, since many of them address precisely the types of problems that many pre-processors also fix. Template-strings, custom elements, etc. add a huge amount of possibilities for web-application development and imo should get way more attention outside of a small circle of excited people.
- morrvs 6y agoCompletely agree. In hindsight the choice of ES5 is questionable and in the study I actually conclude that another ES6-based experiment is desirable. Also, as others here have noted, you could start with ES6, see if it works for enough of your users, and only if not orthogonally introduce transpilation to ES5 as a production optimization.
- runarberg 6y agoMost of the websites I write these days don’t have a build step for development, only for production. Modern browsers (and modern node) support ES modules, so there is no need to build anything until you ship to a legacy browser. The only pain point of not building during development is when I need to pull in a third party dependency (since node and browsers pull from different sources; and import-maps is not is still not a standard), but if your are not using any third party dependencies, you should be fine.
- austincheney 6y agoIt's amazing that a repository like this is even a thing. A demonstration that you don't need 3 million dependencies and a giant framework to build a simple application in the environment where a language was created to support.
- xwdv 6y agoI don’t see the point really. In the real world applications aren’t “simple”. They are complex.
- austincheney 6y agoIn the real world most JavaScript developers cannot write original code at all.
- xwdv 6y agoIn the real world they don’t really have to. They aren’t building libraries.
- austincheney 6y agoDevelopers that can’t develop. What could go wrong?
- RantyDave 6y agoI'm quite happy to see fewer libraries being developed.
- astura 6y agoSome applications are complex, many are simple (just over-engineered).
- sfrinlan 6y agoI don't know who originally said it but "If you're not using a framework, you're building a framework". This repo even has the following caveat: (2) These usually end up becoming a custom micro-framework, thereby questioning why you didn't use one of the established and tested libraries/frameworks in the first place. That said, I don't hate it. For quite some time, I've taken the stance that a web development team needs an opinionated framework, but it's fine for it to be a bespoke creation rather than off-the-shelf. The biggest value of choosing React, Vue, Svelte, etc is, in my opinion, less about it doing the heavy lifting for you with the DOM and more about adopting an established valid opinion to guide the team's development.
- dukoid 6y agoCan I claim I don't violate the "No general-purpose utility functions related to the DOM/UI" if I use only one such function? O:) https://github.com/stefanhaustein/notemplate https://github.com/stefanhaustein/notemplate (the demo is just TodoMVC, though)
- morrvs 6y ago:D just to be clear, the rules were made just for the case study. I'd never recommend following these rules in a professional project. They are part of the method of the case study, not its outcome; the outcome is a couple of (hopefully) interesting patterns and insights, without trying to prescribe anything.
- morrvs 6y agoThanks for reading - original author here. For the precise quote you mentioned I came up with somewhat format rules which prevented building a framework (code-wise) for this case study. The "caveat" you mention is just an explanation for the chosen ruleset; I believe I haven't introduced any general-purpose DOM/UI code in the case study and instead only describe patterns (correct me if I'm wrong!). I agree with your view of framework value as I professionally use React on a daily basis and will continue to do so, for similar reasons :)
- noir_lord 6y ago
- ddgflorida 6y agoIn your Try it Online demo I could decrease (<) the dates all day long but not increase (>).
- morrvs 6y agoWould you mind creating an issue with some details (browser and version, maybe how to reproduce)? Thanks :)!
- ddgflorida 6y agoIt works fine today!
- z3t4 6y agoThe trick is to stop thinking XML/HTML and instead use functions which returns elements/components. First write the app in spaghetti code, then turn it into pure functions. var app = todoList(data); document.documentElement.appendChild(app);
- brabel 6y agoIn other words, the good old MVC pattern. (M) Model is your `data`. (V) View is what your function returns. (C) Controller is the functions your elements may use to mutate the data.
- srtjstjsj 6y agoMVC doesn't mean "has data, logic, and UI". MVC is a model for how the UI communicates with the data store.
- brabel 6y agoResponding to the wrong comment?? MVC is exactly what I said it is, check it here if you don't know: https://en.wikipedia.org/wiki/Model–view–controller https://en.wikipedia.org/wiki/Model–view–controller
- king_magic 6y ago> There's no custom framework invented here. Proceeds to literally invent a custom framework. It’s interesting, but I’ll stick with Vue/React.
- morrvs 6y agoOriginal author here. During the study, I explicitly forbid myself from writing general-purpose helpers which would make up a framework. Would you mind elaborating what in your view makes up the "custom framework"? Thanks!
- Joker_vD 6y agoIf general-purpose helpers make up a framework, then what is the difference between a library and a framework? I'm pretty sure jQuery is not a framework.
- morrvs 6y agoSorry, I didn't mean to make a difference between frameworks and libraries in this case; both would violate the method/goal of the case study which was finding vanilla patterns that are not dependant on general-purpose code.
- conscion 6y agoNot OP, but in my reading of your case study, you still made a framework. Instead of having a code-based framework, where the methods and classes enforce how you implement your system - you created a convention-based framework (use a specific CSS naming technique, model your JS on this template, etc.).
- tobr 6y agoIsn't a “convention-based framework” just... a convention? With such a generous definition of “framework”, is it even realistic to solve this problem without accidentally creating one? Would you need to purposefully avoid any type of consistency between the different modules, and solve the same problem in different ways if it comes up more than once?
- dsego 6y agoAnother good guide to mvc with js is this one https://github.com/madhadron/mvc_for_the_web https://github.com/madhadron/mvc_for_the_web The neat thing is that it starts from scratch and adds things, like pub/sub, then models, controllers and so on.
- morrvs 6y agoIt does start from scratch but it (re-)invents a whole lot of general-purpose code, in effect making up a framework/library, which was an explicit non-goal for the case study (because there are good ones already).
- dsego 6y agoI didn't have time before to go through your case study. But after looking at it for a bit, it doesn't look that much different from the mvc example I linked. It seems that you are leveraging the built-in event system for observers and using the dom for referencing your components. Personally, I don't feel that mvc for the web is inventing a whole lot more, just patterns and some utilities. Having events that bubble from the child component up to the app component is an interesting approach. It simplifies the code by not having to pass controllers into views, but makes the child components less reusable in other contexts. Btw, this structure also reminds me of backbone(1) and that riotjs 1kb blog post from ages ago(2). I love the effort and thank you for making it. (1) https://backbonejs.org/#View https://backbonejs.org/#View (2) https://muut.com/blog/technology/riotjs-the-1kb-mvp-framework.html https://muut.com/blog/technology/riotjs-the-1kb-mvp-framewor....
- thomasfromcdnjs 6y agoI read it all despite my short attention span. Beautifully written study. I hope to leave productive feedback later. I do hope people don't miss the point that I think OP was trying to be modest about. This study is not for or against frameworks, it is a detailed and informative reflection of the current state of client JavaScript.
- morrvs 6y agoThank you very much, looking forward to your feedback! And yes, this is exactly what I wanted to achieve :)
- mark_and_sweep 6y agoOops, I expected vanilla web development to mean server-rendered HTML with forms. Thanks for making me feel old.
- throw_m239339 6y agoand Perl CGI. That's all a developer needs!
- gumby 6y agoI have written (internal) production CGI in bash.
- morrvs 6y agoSorry :D nothing wrong with server-rendered HTML and forms for many use cases. Unfortunately, by the limits of connectivity, if you want to build something that is interactive, data-driven, and responsive at the same time you will always be forced to render on the client-side at some point.
- falcolas 6y ago> if you want to build something that is interactive, data-driven, and responsive at the same time you will always be forced to render on the client-side I'm not sure I personally agree with this blanket statement. Connection times can be, for a vast majority of users, measured in tens of milliseconds, giving us a pretty good budget for processing and rendering while still appearing to be "instantaneous" (100ms) or "fluid" (1s). Even the worst case connection times (satellite & mobile) are still measurable using hundreds of milliseconds. The worst ranked countries still average in excess of 1.5 Mbps transmission rates - more than enough for compressed text. And, given how unresponsive so many "top 100" SSA pages are (such as blogs that take whole seconds to display their initial content), I can't agree that doing that processing on the server would actually be less interactive or responsive. Even the test application from this article can load from scratch in under a second, most of that time being the DNS resolution and the server processing for serving the page.
- fctorial 6y agoWhy is there an fps counter at the top right?
- morrvs 6y agoPerformant drag & drop + FLIP animations were not trivial to implement (naive approaches like re-render fully on each mousemove fail spectacularly). I needed to see FPS on a couple different devices so I added the counter. Also, since I claim good rendering performance in the case study, I just kept it there as "proof" :)
- lynndotpy 6y agoI appreciate this project a lot! As someone exploring webdev as a hobby, everything is new to me and there are a variety of frameworks. I'm hesitant to start from somewhere that isn't "vanilla". As someone only a little familiar with JavaScript, the script seems surprisingly comprehensible.
- morrvs 6y agoGlad you liked it and could follow through!
- boplicity 6y agoOn a side note, the TeuxDeux app they cloned is wonderful. It immediately clicked for me. As someone who's been managing five big projects simultaneously, this is going to significantly help with cognitive load. I love the lists below the calendar.
- morrvs 6y agoTotally agree. I should update the study to express praise for the original TeuxDeux, it's conceptually the best to-do app out there in my opinion.
- twodave 6y ago> Data flows downwards, actions flow upwards I know I'm nitpicking here, but I always find this phrase confusing, and I think this way of explaining unidirectional data-flow is problematic for those new to the concept. If you want to persist something from a child component, the message that represents the action contains the data needed to make that state change, which sort of exposes the flaws in the up/down analogy. Unidirectional data flow doesn't have an "up" and a "down". It doesn't even follow a single path. It's more like a ladder with several water slides connected to it. The pool is where the state lives. The slides are the child components. The people are the data. Climbers are performing state propagation. People who are sliding are creating actions. People who are landing back in the pool are updating the state. Edit: no, it's not lost on me that the example I ended up using involves up and down motion--it's just not a very easy concept to convey using real-life analogies (which I think also contributes to the learning curve).
- okaleniuk 6y agoI love it! It's definitely an exercise worth taking. Nice transfer size, and I'm happy to see that the code is quite maintainable. I do my wordsandbuttons.online in similar spirit: no dependencies, and all the pages are kept below 64KB. However, as the code base grows, I'm starting to employ scripts to do the grunt work for me. So while I don't have dependencies per se, code patterns become dependency it its own right.
- morrvs 6y agoMany thanks :) like the concept of your site, I will take a look some time
- dzonga 6y agoas someone who has made money as front-end developer, & saw the error in my ways. I will say the industry is not interested in simpler things. they're not interested in making the web faster for everyone. your typical insert framework here web app is slow on a laptop and even worse on mobile. now throw in hiring, it means everyone thinks their app should be on react or whatever, when it doesn't warrant it to be. look at Basecamp for apps that work without a major framework. things like htmx exist but community is small. so yeah, props to the author for making a proposition for something that would work. but nah, frontend work this days is about making everything complex from getting the project running to the build steps and even deploying the project. though one area, I will say frontend is now better on is testing: cypress, jest and react-testing library are nice things to work with.
- spark85 6y agoAre Web Components (https://developer.mozilla.org/en-US/docs/Web/Web_Components https://developer.mozilla.org/en-US/docs/Web/Web_Components) considered to be a library/framework? If not have you considered trying to update the repo to use them
- morrvs 6y agoNo, I'd consider them a standard and a candidate for implementing the case study. When I started the study I was thrown off by this: https://caniuse.com/?search=components https://caniuse.com/?search=components - and very huge polyfills. In hindsight I'm not sure if I dismissed WC too quickly. This is probably thin ice, especially since I've never built anything with WC, but they always seemed slightly over-engineered. I will try to learn about WC a bit more and maybe elaborate on my reasoning here.
- spankalee 6y agoThat page shows excellent support! Web components are supported in all current browsers. Unless you support IE11 you don't need to worry about polyfills.
- armandososa 6y agoThis is odd (public/scripts/TodoList.js): el.innerHTML = [ '<div class="items"></div>', '<div class="todo-item-input"></div>', ].join('\n'); I wonder why aren't they using `DOM.createElement` instead of innerHTML since they will query for those nodes later anyway.
- morrvs 6y agoI've tried but I (surprisingly) found the string array to be the most readable way to do it without helpers. It's also easily replaced by ES6 templates when upgrading.
- masswerk 6y agoCounterintuitive fun fact: `HTMLElement.innerHTML = "string"` tends to be faster than `document.createElement()`.
- d_burfoot 6y ago> Naively re-rendering a whole component using .innerHTML should be avoided as this may hurt performance and will likely break important functionality such as input state, focus, text selection etc. which browsers have already been optimizing for decades. I think this statement deserves some serious scrutiny. In many cases the performance hit may not be relevant or noticeable. I know this because I've been very productively using the following approach to build dynamic webapps for my personal use: 1. Compose HTML strings using Javascript, especially with string interpolation 2. Slap the resulting strings into div/span elements with innerHTML= statements. This approach results in extremely clean and simple code - much cleaner than the OP's code in my view. I have never noticed any kind of performance issues, the updates are always instantaneous. I don't know what the author means by breaking functionality like text selection and focus, but it's never been relevant for me. For an example of the coding style, see the reDispActiveTable in this code, which draws a table of TODO list items with some operations like edit/delete/mark complete. https://github.com/comperical/WebWidgets/blob/main/gallery/minitask/widget.jsp#L296 https://github.com/comperical/WebWidgets/blob/main/gallery/m...
- eliseumds 6y agoThat's what OP means: https://codesandbox.io/s/elastic-rubin-hxpcw?file=/src/index.js https://codesandbox.io/s/elastic-rubin-hxpcw?file=/src/index... And that's why reconciliation algorithms became so popular. You can't be serious when you say that losing input focus and text selection have never been relevant to you. Basically, dealing with the internal state of components down the tree becomes a nightmare.
- simlan 6y agoNot a js wiz but i really enjoyed your experimental approach and the write up. Stating the objectives and constraints, report results. Nicely done!
- superkuh 6y agoI know in this community the overloaded value for vanilla in this context means just javascript without other people's javascript. But "vanilla web" should really mean HTML and CSS.
- dbtc 6y agono js = just html and css no framework js = topic of this link vanilla = a bean, or a flavor
- txutxu 6y agoIn the software sense, vanilla means "in it's original form, without addons, modifications, abstractions, third party libraries, ...". Like a "vanilla kernel" is a Linux kernel without (distributor) patches. Or a "vanilla debian" is a Debian system without third party repositories or software. Regarding parent, I could say... you cannot make a permanent To-Do web app, with HTML+CSS... drag and drop? data persistence? you need a backend (and JS for event handling) or as in this case local storage via JS. OK, you can make a simple To-Do with static forms being sent to a backend... but then you have HTML+CSS+something (java, python, php, ruby, perl, golang, whatever), not only HTML+CSS.
- horsawlarway 6y agoSure, so which subset of HTML are we talking about? Because unless I'm misremembering things, HTML 2.0 (literally the first version intended to be a standard going forwards) came out exactly the same year that JS dropped in a commercial browser (1995), and superseded the previous HTML and HTML+ markups. So surely you don't mean HTML with things like file uploads, or GIF support. Because that's not "vanilla" in your world. /s
- superkuh 6y ago/s all you want but the distinction between documents and applications is clear.
- 6y ago
- ilaksh 6y agoWhy does it have to be fully animated? I feel like 44k is a lot if it's just a sortable list with checkboxes. I saw a draggable package on mom that is less than 2k. Does Vanilla mean we can't use npm or we pack or browserify or anything?
- morrvs 6y agoIt does not have to be. However, animations greatly contribute to UX, and are an interesting cross-cutting concern to implement (with any tech). Remember that 44K is unminified, unoptimized, with considerable duplication, and includes HTML, CSS, JS, and SVG icons.
- megous 6y agoNot separating the state from the DOM (more than necessary, that is - at the client/server boundary) makes a bunch of things much easier. You can just manipulate the DOM and the state stays with the DOM, so there's nothing to sync internally within the JS app. You only serialize from DOM and to DOM at the server API boundary. No need for the "rendering" in response to state changes. You just change the DOM intuitively, and that's that. And that makes "vanilla" browser apps easier to write too.
- morrvs 6y agoThanks to everyone who took the time to read it, and thank you all so much for all the feedback! I'm quite overwhelmed by the response :) looking to address as much of the feedback as possible by the end of the week. A major weakness seems to be my choice of ES5. I wanted an almost absolute minimum, which ES5 seemed to be at the time. I was lead by the fact that most bundlers produce ES5 by default, which may very well have been a mistake. Interestingly, if ES5 is really dead (which it might be, I'm not sure) and ES6 is the minimum target, the study's results would actually improve drastically (less verbosity, actual modules, etc.) and further support the claim that vanilla can be maintainable (even without build steps). For anyone interested, let's continue the discussion here: https://github.com/morris/vanilla-todo/issues/6 https://github.com/morris/vanilla-todo/issues/6
- sajb 6y agoWill uncompleted tasks move over to the next day?
- sajb 6y agoNope, apparently not.
- ribaldev 6y agoWe use task management apps to save us time and give more visibility over the work. However, the app can become so complicated to use by itself, that we may choose to go for very basic note-taking apps to avoid the complexity. I was looking for a minimal, simple and user-friendly app for daily task management, so I developed Renoj. Fast to-do task management in Desktop for ultimate productivity. Website: https://ribal.dev/renoj https://ribal.dev/renoj
- dottedmag 6y ago15ms to draw an empty table for a week's schedule, and 40ms during animation seems... excessive?