javascript

  • Async iteration and for await…of

    Consuming a paginated API meant a while loop with a mutable cursor and a manual termination condition, all of it in the caller. The pagination logic ends up…

  • webpack mode, and the eighty lines it deletes

    A v2 production configuration declared UglifyJs, the NODE_ENV define, module concatenation and the no-errors plugin by hand, and every project copied a slightly different version of the same…

  • webpack 4 needs almost no configuration

    One line replaced about eighty. The defaults are almost always right, and the cost is that they are invisible when they are not.

  • Promise.finally is the one everyone wrote by hand

    Turning off a loading spinner has to happen on both the success and the failure path, so it got duplicated into then and catch, and one of the…

  • Bootstrap 4 dropped the float grid

    Two and a half years in alpha, and the grid is flexbox now. The class renames are mechanical; the ones that changed meaning rather than name are not.

  • try/catch around await catches a rejection

    A rejected promise inside an async function behaves like a thrown exception, which means error handling stops being a .catch() bolted onto the end of a chain and…

  • String padStart for formatting without a library

    Zero-padding a number has been a slice of a string of zeros concatenated with the value, which is short enough to write inline and long enough to get…

  • Portals for the modal that must escape its parent

    A modal rendered where it logically belongs is trapped by any ancestor with overflow: hidden, a transform, or a z-index stacking context — and moving it in the…

  • Code splitting with dynamic import

    Shipping the checkout code to everyone who visits the homepage is the default, because a single entry point produces a single bundle. A dynamic import is a split…

  • Enqueue in the footer unless it must block

    The fifth argument to wp_enqueue_script() decides whether the tag goes in the head, where it blocks parsing, or before </body>, where it does not. The default is the…