javascript

  • IntersectionObserver replaces the scroll listener

    Detecting whether an element is on screen has meant a scroll handler calling getBoundingClientRect(), which forces a synchronous layout on every scroll event and is the classic cause…

  • jQuery 3 deferreds finally follow Promises/A+

    A jQuery Deferred used to swallow exceptions thrown in a then callback and call its handlers synchronously if already resolved. Version 3 made both behave the way native…

  • webpack loaders run right to left

    A loader chain reads like a pipeline and executes like function composition, which is the opposite direction. The last entry in the array runs first. Sass compiles to…

  • keys in a React list are an identity claim

    The warning about missing keys makes them look like a lint requirement to be silenced with the array index. A key tells React which element in the new…

  • Debounce a function with ES6

  • Lazy-load images with IntersectionObserver

  • class in JavaScript is prototypes with better syntax

    class introduced no new object model. It is syntax over the prototype chain, which explains most of the behaviour that surprises people coming from other languages. Methods are…

  • Promise.race is how you write a timeout

    A fetch with no timeout waits as long as the browser is willing to, which on a bad mobile connection is a very long time. There is no…

  • Vue 2 render functions are the escape hatch from templates

    Vue templates cover almost everything and become awkward at exactly one point: rendering a different element depending on a prop, which turns into a chain of v-if blocks…

  • Passive event listeners stop the scroll jank

    A touchstart or wheel listener can call preventDefault(), so the browser cannot begin scrolling until the handler has run. Every such listener therefore delays scrolling, whether or not…