Vanilla is the best flavour
I know. There were even jokes about it. But this is a little story about how and why I learned to love the web platform. There are no accouterments, no hint-of-cardamom, and not even a sprig of mint.
The first thing I realised is that the web platform is really high quality vanilla. We are not talking about that yellow crap you get from the supermarket, or even that Mr Whippy (soft serve) human-rights violation. This is hand-made Cornish creamy-with-black-specs.
So, what’s great?
HTML5 came, and stayed, and matured. Now, HTML5 is one of the worst named things ever. It should have been called a sane thing like DOM2 or, let’s see “Better Web APIs” or something, but HTML5 has almost nothing to do with HTML, which has barely changed apart from some semantic elements that don’t really matter to me: <nav>, <section>, etc.
HTML5 came with some incredible APIs:
- IndexedDB API. Again, no idea what this means from the name, but IndexedDB is a local object like key-value store with indexes and transactions. It is available on just about any modern browser. I tried idb-keyval, Dexie.js, and others. Again good libraries all around. This time my vanilla implementation was about 40 lines. I have one database, 2 tables, and very simple get and set requirements. No deletes are required and I use transactions very naively.
- AppCache. I’m going to get some heat for this, because AppCache is broken. But AppCache is a way of telling browsers to “cache this shit” and for extremely basic use-cases of storing html, css, js, and other assets, it works extremely well. Oh sure, it can’t handle re-entrant querystring blah blah blah, but it is available on iOS Safari. The use-case for AppCache has more recently been solved by Service Worker which is a more complex and flexible API, and certainly the future. But I challenge anyone to tell me how “Service worker is not available on iOS Safari” is LESS broken than “AppCache is a bit broken everywhere”. There is literally no comparison. I need to drive to the supermarket. I have a broken car OR I have no car.
- Events. I love js-signals. It’s a fantastic library which is well thought out, mature and tiny. I was using it exactly for two separate signals. But, I didn’t use any of the fancy features. In fact, I realised all I needed is: window.dispatchEvent(new Event(‘my-event’)). Goodness me. That’s all. Since then, I stopped using js-signals.
- InnerHTML/textContent. Yeah, I know. I was using Vue, which is again an amazing library. It is compact and has a huge number of awesome features. But I was using it to update exactly 3 divs at a very predictable time, i.e., when I receive my data from the web or local storage. This was quickly replaced with myElement.textContent = mydata;. Yes, that’s all. 3 lines of code and no brain power required to know what my data object is, reactive properties, Vue’s model, etc. etc.
As I learn the web platform more and more, I find more of these areas where I eventually save time and space just eating vanilla. The true benefit is that I am learning something. I am not learning how to use your awesome libraries, which is awesome in itself. I am learning how to use the web platform, which has specifications that will be around for many years. I am future proofing my knowledge, and making a sound educational investment.
Thanks for reading.