Awesomplete: 2KB autocomplete with zero dependencies
Sorry for the lack of posts for the past 7 (!) months, Iâve been super busy working on my book, which up to a certain point, I couldnât even imagine finishing, but Iâm finally there! Iâve basically tried to cram all the CSS wisdom Iâve accumulated over the years in it :P (which is partly why it took so long, I kept remembering more things that just *had* to be in it. Its page count on the OâReilly website had to be updated 3 times, from 250 to 300 to 350 and it looks like the final is gonna be closer to 400 pages) and itâs gonna be super awesome (preorder here!) :D . I have been posting a few CSS tricks now and then on my twitter account, but havenât found any time to write a proper blog post.
Anyhow, despite being super busy with MIT (which btw is amazing, challenging in a good way, and full of fantastic people. So glad to be here!) and the book, I recently needed an autocomplete widget for something. Surprisingly, I donât think I ever had needed to choose one in the past. Iâve worked with apps that had it, but in those cases it was already there.
At first, I didnât fret. Finally, a chance to use the HTML5 <datalist>
, so exciting! However, the more I played with it, the more my excitement was dying a slow death, taking my open web standards dreams and hopes along with it. Not only itâs incredibly inconsistent across browsers (e.g. Chrome matches only from the start, Firefox anywhere!), itâs also not hackable or customizable in any way. Not even if I got my hands dirty and used proprietary CSS, I still couldnât do anything as simple as changing how the matching happens, styling the dropdown or highlighting the matching text!
So, with a heavy heart, I decided to use a script. However, when I looked into it, everything seemed super bloated for my needs and anything with half decent usability required jQuery, which results in even more bloat.
So, I did what every crazy person with a severe case of NIH Syndrome would: I wrote one. It was super fun, and I donât regret it, although now Iâm even more pressed for time to meet my real deadlines. I wrote it primarily for myself, so even if nobody else uses it, ho hum, it was more fun than alternative ways to take a break. However, itâs my duty to put it on Github, in case someone else wants it and in case the community wants to take it into its loving, caring hands and pull request the hell out of it.
To be honest, I think itâs both pretty and pretty useful and even though it wonât suit complex needs out of the box, itâs pretty hackable/extensible. I even wrote quite a bit of documentation at some point this week when I was too sleepy to work and not sufficiently sleepy to sleep â because apparently thatâs what was missing from my life: even more technical writing.
I saved the best for last: Itâs so lightweight you might end up chasing it around if thereâs a lot of wind when you download it. Itâs currently a little under 1.5KB minified & gzipped (the website says 2KB because it will probably grow with commits and I donât want to have to remember to update it all the time), with zero dependencies! :D
And itâs even been verified to work in IE9 (sorta), IE10+, Chrome, Firefox, Safari 5+, Mobile Safari!
PS: If youâre about to leave a comment on how itâs not called âautocompleteâ, but âtypeaheadâ, please go choke on a bucket of cocks instead. :P