More from Jim Nielsen’s Blog
Authentication on the web is a complicated problem. If you’re going to do it yourself, there’s a lot you have to take into consideration. But odds are, you’re building an app whose core offering has nothing to do with auth. You don’t care about auth. It’s an implementation detail. So rather than spend your precious time solving the problem of auth, you pay someone else to solve it. That’s the value of SaaS. What would be the point of paying for an authentication service, like workOS, then re-implementing auth on your own? They have dedicated teams working on that problem. It’s unlikely you’re going to do it better than them and still deliver on the product you’re building. There’s a parallel here, I think, to building stuff in the browser. Browsers provide lots of features to help you deliver good websites fast to an incredibly broad and diverse audience. Browser makers have teams of people who, day-in and day-out, are spending lots of time developing and optimizing new their offerings. So if you leverage what they offer you, that gives you an advantage because you don’t have to build it yourself. You could build it yourself. You could say “No thanks, I don’t want what you have. I’ll make my own.” But you don’t have to. And odds are, whatever you do build yourself, is not likely to be as fast as the highly-optimized subsystems you can tie together in the browser. And the best part? Unlike SasS, you don’t have to pay for what the browser offers you. And because you’re not paying, it can’t be turned off if you stop paying. @view-transition, for example, is a free API that’ll work forever. That’s a great deal. Are you taking advantage? Email · Mastodon · Bluesky
I have a standing desk that goes up and down via a manual crank. I’ve had it for probably ten years. Every time I raise or lower that thing, it gets my blood pumping. I often think: “I should upgrade to one of those standing desks that goes up and down with the push of a button.” Then there’s the other voice in my head: “Really? Are you so lazy you can’t put your snacks down, get out of your comfy chair, in your air conditioned room, and raise or lower your desk using a little elbow grease? That desk is just fine.” While writing this, I get out of my chair, star the timer, and raise my desk to standing position. 35 seconds. That’s the cost: 35 seconds, and an elevated heart rate. As I have many times over the last ten years, I recommit to keeping it — mostly as a reminder that it’s ok to do some things manually. Not everything in my life needs to be available to me at the push of a button. Email · Mastodon · Bluesky
(I present to you my stream of consciousness on the topic of casing as it applies to the web platform.) I’m reading about the new command and commandfor attributes — which I’m super excited about, declarative behavior invocation in HTML? YES PLEASE!! — and one thing that strikes me is the casing in these APIs. For example, the command attribute has a variety of values in HTML which correspond to APIs in JavaScript. The show-popover attribute value maps to .showPopover() in JavaScript. hide-popover maps to .hidePopover(), etc. So what we have is: lowercase in attribute names e.g. commandfor="..." kebab-case in attribute values e.g. show-popover camelCase for JS counterparts e.g. showPopover() After thinking about this a little more, I remember that HTML attributes names are case insensitive, so the browser will normalize them to lowercase during parsing. Given that, I suppose you could write commandFor="..." but it’s effectively the same. Ok, lowercase attribute names in HTML makes sense. The related popover attributes follow the same convention: popovertarget popovertargetaction And there are many other attribute names in HTML that are lowercase, e.g.: maxlength novalidate contenteditable autocomplete formenctype So that all makes sense. But wait, there are some attribute names with hyphens in them, like aria-label="..." and data-value="...". So why isn’t it command-for="..."? Well, upon further reflection, I suppose those attributes were named that way for extensibility’s sake: they are essentially wildcard attributes that represent a family of attributes that are all under the same namespace: aria-* and data-*. But wait, isn’t that an argument for doing popover-target and popover-target-action? Or command and command-for? But wait (I keep saying that) there are kebab-case attribute names in HTML — like http-equiv on the <meta> tag, or accept-charset on the form tag — but those seem more like legacy exceptions. It seems like the only answer here is: there is no rule. Naming is driven by convention and decisions are made on a case-by-case basis. But if I had to summarize, it would probably be that the default casing for new APIs tends to follow the rules I outlined at the start (and what’s reflected in the new command APIs): lowercase for HTML attributes names kebab-case for HTML attribute values camelCase for JS counterparts Let’s not even get into SVG attribute names We need one of those “bless this mess” signs that we can hang over the World Wide Web. Email · Mastodon · Bluesky
I’ve written previously about reloading a document using only HTML but that got me thinking: What are all the values you can put in an anchor tag’s href attribute? Well, I looked around. I found some things I already knew about, e.g. Link protocols like mailto:, tel:, sms: and javascript: which deal with specific ways of handling links. Protocol-relative links, e.g. href="//" Text fragments for linking to specific pieces of text on a page, e.g. href="#:~:text=foo" But I also found some things I didn’t know about (or only vaguely knew about) so I wrote them down in an attempt to remember them. href="#" Scrolls to the top of a document. I knew that. But I’m writing because #top will also scroll to the top if there isn’t another element with id="top" in the document. I didn’t know that. (Spec: “If decodedFragment is an ASCII case-insensitive match for the string top, then return the top of the document.”) href="" Reloads the current page, preserving the search string but removing the hash string (if present). URL href="" resolves to /path/ /path/ /path/#foo /path/ /path/?id=foo /path/?id=foo /path/?id=foo#bar /path/?id=foo href="." Reloads the current page, removing both the search and hash strings (if present). Note: If you’re using href="." as a link to the current page, ensure your URLs have a trailing slash or you may get surprising navigation behavior. The path is interpreted as a file, so "." resolves to the parent directory of the current location. URL href="." resolves to /path / /path#foo / /path?id=foo / /path/ /path/ /path/#foo /path/ /path/?id=foo /path/ /path/index.html /path/ href="?" Reloads the current page, removing both the search and hash strings (if present). However, it preserves the ? character. Note: Unlike href=".", trailing slashes don’t matter. The search parameters will be removed but the path will be preserved as-is. URL href="?" resolves to /path /path? /path#foo /path? /path?id=foo /path? /path?id=foo#bar /path? /index.html /index.html? href="data:" You can make links that navigate to data URLs. The super-readable version of this would be: <a href="data:text/plain,hello world"> View plain text data URL </a> But you probably want data: URLs to be encoded so you don’t get unexpected behavior, e.g. <a href="data:text/plain,hello%20world"> View plain text data URL </a> Go ahead and try it (FYI: may not work in your user agent). Here’s a plain-text file and an HTML file. href="video.mp4#t=10,20" Media fragments allow linking to specific parts of a media file, like audio or video. For example, video.mp4#t=10,20 links to a video. It starts play at 10 seconds, and stops it at 20 seconds. (Support is limited at the time of this writing.) See For Yourself I tested a lot of this stuff in the browser and via JS. I think I got all these right. Thanks to JavaScript’s URL constructor (and the ability to pass a base URL), I could programmatically explore how a lot of these href’s would resolve. Here’s a snippet of the test code I wrote. You can copy/paste this in your console and they should all pass 🤞 const assertions = [ // Preserves search string but strips hash // x -> { search: '?...', hash: '' } { href: '', location: '/path', resolves_to: '/path' }, { href: '', location: '/path/', resolves_to: '/path/' }, { href: '', location: '/path/#foo', resolves_to: '/path/' }, { href: '', location: '/path/?id=foo', resolves_to: '/path/?id=foo' }, { href: '', location: '/path/?id=foo#bar', resolves_to: '/path/?id=foo' }, // Strips search and hash strings // x -> { search: '', hash: '' } { href: '.', location: '/path', resolves_to: '/' }, { href: '.', location: `/path#foo`, resolves_to: `/` }, { href: '.', location: `/path?id=foo`, resolves_to: `/` }, { href: '.', location: `/path/`, resolves_to: `/path/` }, { href: '.', location: `/path/#foo`, resolves_to: `/path/` }, { href: '.', location: `/path/?id=foo`, resolves_to: `/path/` }, { href: '.', location: `/path/index.html`, resolves_to: `/path/` }, // Strips search parameters and hash string, // but preserves search delimeter (`?`) // x -> { search: '?', hash: '' } { href: '?', location: '/path', resolves_to: '/path?' }, { href: '?', location: '/path#foo', resolves_to: '/path?' }, { href: '?', location: '/path?id=foo', resolves_to: '/path?' }, { href: '?', location: '/path/', resolves_to: '/path/?' }, { href: '?', location: '/path/?id=foo#bar', resolves_to: '/path/?' }, { href: '?', location: '/index.html#foo', resolves_to: '/index.html?'} ]; const assertions_evaluated = assertions.map(({ href, location, resolves_to }) => { const domain = 'https://example.com'; const expected = new URL(href, domain + location).toString(); const received = new URL(domain + resolves_to).toString(); return { href, location, expected: expected.replace(domain, ''), received: received.replace(domain, ''), passed: expected === received }; }); console.table(assertions_evaluated); Email · Mastodon · Bluesky
After shipping my work transforming HTML with Netlify’s edge functions I realized I have a little bug: the order of the icons specified in the URL doesn’t match the order in which they are displayed on screen. Why’s this happening? I have a bunch of links in my HTML document, like this: <icon-list> <a href="/1/">…</a> <a href="/2/">…</a> <a href="/3/">…</a> <!-- 2000+ more --> </icon-list> I use html-rewriter in my edge function to strip out the HTML for icons not specified in the URL. So for a request to: /lookup?id=1&id=2 My HTML will be transformed like so: <icon-list> <!-- Parser keeps these two --> <a href="/1/">…</a> <a href="/2/">…</a> <!-- But removes this one --> <a href="/3/">…</a> </icon-list> Resulting in less HTML over the wire to the client. But what about the order of the IDs in the URL? What if the request is to: /lookup?id=2&id=1 Instead of: /lookup?id=1&id=2 In the source HTML document containing all the icons, they’re marked up in reverse chronological order. But the request for this page may specify a different order for icons in the URL. So how do I rewrite the HTML to match the URL’s ordering? The problem is that html-rewriter doesn’t give me a fully-parsed DOM to work with. I can’t do things like “move this node to the top” or “move this node to position x”. With html-rewriter, you only “see” each element as it streams past. Once it passes by, your chance at modifying it is gone. (It seems that’s just the way these edge function tools are designed to work, keeps them lean and performant and I can’t shoot myself in the foot). So how do I change the icon’s display order to match what’s in the URL if I can’t modify the order of the elements in the HTML? CSS to the rescue! Because my markup is just a bunch of <a> tags inside a custom element and I’m using CSS grid for layout, I can use the order property in CSS! All the IDs are in the URL, and their position as parameters has meaning, so I assign their ordering to each element as it passes by html-rewriter. Here’s some pseudo code: // Get all the IDs in the URL const ids = url.searchParams.getAll("id"); // Select all the icons in the HTML rewriter.on("icon-list a", { element: (element) => { // Get the ID const id = element.getAttribute('id'); // If it's in our list, set it's order // position from the URL if (ids.includes(id)) { const order = ids.indexOf(id); element.setAttribute( "style", `order: ${order}` ); // Otherwise, remove it } else { element.remove(); } }, }); Boom! I didn’t have to change the order in the source HTML document, but I can still get the displaying ordering to match what’s in the URL. I love shifty little workarounds like this! Email · Mastodon · Bluesky
More in literature
Dan Brown is a UK-based bowyer who loves crafting English longbows from yew wood. He carved his first ever yew longbow at age 15 and has been obsessed with the craft ever since. Now with a new workshop in the making, he hopes that he can turn his hobby into a career and make bows full-time.
Cette fois, c’est différent C’est l’histoire d’une rencontre entre un ingénieur et un financier. Plein de rêves, l’ingénieur dessine des plans dont la réalisation pourrait changer le monde. Séduit, le financier se décide à les réaliser. Utilisant son réseau, il arrive à lever des fonds auprès d’investisseurs connus. Le projet prend de l’ampleur et, très vite, entre en bourse avec plusieurs émissions d’actions. Alors que notre ingénieur explore le monde pour nouer les partenariats nécessaires à la réalisation de son projet, le financier, lui, mène une campagne médiatique sans précédent. Il va jusqu’à racheter un journal afin de lui dicter une ligne éditoriale favorable à son projet. Il noue avec d’autres médias des partenariats et crée de toutes pièces des nouveaux médias centrés sur les conseils boursiers afin de mettre son propre projet en avant. Cela fonctionne, le cours de l’action s’envole. La valorisation est tout simplement incroyable ! Et pour cause : notre financier manipule habilement les taux en rachetant ses propres actions grâce à des hommes de paille et des mécanismes circulaires. En clair: l’argent des souscripteurs d’actions sert à la société pour acheter ses propres actions. Ce qui fait monter les cours. Et augmente la trésorerie vu que la société est propriétaire de ses propres actions ! Ces mouvements d’argent et ces mécanismes d’écriture permettent à l’entreprise d’annoncer des bénéfices plantureux. Il faut bien avouer qu’avec un conseil d’administration composé des plus grands investisseurs de ces dernières années, avec ses somptueux bureaux ultramodernes et ses milliers d’employés, l’entreprise s’est très vite imposée comme une des plus grosses de la place boursière, une valeur sûre « trop grande pour échouer ». On ne parle que de l’entreprise dans les salons. Les petits actionnaires raclent leurs fonds de tiroir pour acheter des actions ! Le projet prend une telle ampleur que le financier et l’ingénieur en deviennent mystiques. Ils sont persuadés d’être investis d’une mission divine. Ils vont littéralement changer l’humanité, l’amener dans une nouvelle ère ! Leur garde rapprochée ne fait qu’abonder dans ce sens, éblouie par les richesses et les honneurs. Personne ne semble remarquer qu’il n’y a que peu ou prou de revenus réels de la part des clients. D’ailleurs, les moindres critiques ne peuvent provenir que de jaloux ou d’aigris qui ne comprennent pas l’importance primordiale de cette « mission divine ». Des laissés pour compte qui ne veulent pas entendre qu’il faut embarquer ou être laissé à quai. Bon, évidemment, raconté comme cela, vous voyez immédiatement que cela va mal finir. Que cela ne peut pas bien se finir. Heureusement, ce n’est qu’une histoire. Celle de « L’argent », le roman d’Émile Zola paru en 1891, il y a 135 ans ! Histoire inspirée par le krach bien réel de l’Union Générale, en 1881. Un dicton dit qu’en finance, le plus gros mensonge est « Cette fois-ci, c’est différent ». Les décors et les accessoires se modifient, mais, invariablement, la même histoire se répète depuis des siècles. 1929, dot-com, subprimes, FTX : sempiternelle ritournelle ! Pourtant, autour de moi, je n’entends qu’une chose : « Cette fois, c’est différent ! » À propos de l’auteur : Je suis Ploum et je viens de publier Bikepunk, une fable écolo-cycliste entièrement tapée sur une machine à écrire mécanique. Pour me soutenir, achetez mes livres (si possible chez votre libraire) ! Recevez directement par mail mes écrits en français et en anglais. Votre adresse ne sera jamais partagée. Vous pouvez également utiliser mon flux RSS francophone ou le flux RSS complet.
A recent dream was nearly a literal transcription of a real event. Usually my dreams are a vulgar rehash of Max Ernst paintings. It was early evening in winter, already dark. We were still living in Saratoga Springs, N.Y., and I went for a walk. Much snow had fallen and the street was flanked by tall walls of snow, thrown there by the plows. As I crunched down the street I realized Nabokov was correct: snow is blue at night. It nearly glowed blue like a child’s nightlight. Nice to have Nabokov’s observation confirmed in a dream. He returned to the metaphor several times. In Canto I of the poem that lends Pale Fire its title, John Shade writes: “Retake the falling snow: each drifting flake Shapeless and slow, unsteady and opaque, A dull dark white against the day's pale white And abstract larches in the neutral light. And then the gradual and dual blue As night unites the viewer and the view . . .” Nabokov revels in unexpected and precisely observed colors, well beyond the conventional palette. In Lectures on Russian Literature (1980) he writes: “It was Gogol (and after him Lermontov and Tolstoy) who first saw yellow and violet at all. That the sky could be pale green at sunrise, or the snow a rich blue on a cloudless day, would have sounded like heretical nonsense to your so-called ‘classical’ writer, accustomed as he was to the rigid conventional color-schemes of the Eighteenth Century French school of literature.” The best known use of the blue/snow metaphor comes in Pnin (1957) where he reverses it: “A score of small butterflies, all of one kind, were settled on a damp patch of sand, their wings erect and closed, showing their pale undersides with dark dots and tiny orange-rimmed peacock spots along the hindwing margins; one of Pnin’s shed rubbers disturbed some of them and, revealing the celestial hue of their upper surface, they fluttered around like blue snowflakes before settling again.” Nabokov named the endangered species in 1943 -- Lycaeides melissa samuelis. The Karner Blue takes its common name from the hamlet of Karner, already extinct, in the Albany Pine Bush in upstate New York. As a reporter I wrote about the butterfly and its shrinking habitat. Shortly before I arrived, a chunk of the Pine Bush had been lost to a shopping mall. This unique ecosystem, rooted in deposits of glacial sand, is surrounded by pricey real estate. Standing in the middle of blue-stemmed grass, blue lupines, dwarf and prairie willows, blueberries, huckleberries, bush clover, goat’s rue, horse mint, pitch pine and scrub oak, you can hear the traffic on the adjacent New York State Thruway. Only recently did I read “Blue Winter” (Collected Poems, 1936-1976, 1976) by Robert Francis: “Winter uses all the blues there are. One shade of blue for water, one for ice, Another blue for shadows over snow. The clear or cloudy sky uses blue twice - Both different blues. And hills row after row Are colored blue according to how far. You know the bluejay's double-blur device Shows best when there are no green leaves to show. And Sirius is a winterbluegreen star.”