<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Casper Tran</title>
    <description>The latest articles on DEV Community by Casper Tran (@casper_tran_59c6a8b1e1f3d).</description>
    <link>https://dev.to/casper_tran_59c6a8b1e1f3d</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4232116%2F713471b1-5322-4164-a5df-70301a5320fc.jpg</url>
      <title>DEV Community: Casper Tran</title>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/casper_tran_59c6a8b1e1f3d"/>
    <language>en</language>
    <item>
      <title>Adobe Scene7 tells you, in a header, how many bytes AVIF saved</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Tue, 01 Dec 2026 05:50:04 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/adobe-scene7-tells-you-in-a-header-how-many-bytes-avif-saved-5aba</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/adobe-scene7-tells-you-in-a-header-how-many-bytes-avif-saved-5aba</guid>
      <description>&lt;p&gt;Target's product photos come from Adobe's Scene7 image server, and the gallery asks for them like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://target.scene7.com/is/image/Target/GUEST_bd0cfa74-...?wid=1200&amp;amp;hei=1200&amp;amp;qlt=80
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I wanted the stored file, so I fetched six of these photos with curl on 1 December 2026 with a handful of parameter sets. Each request went out twice: once with Chrome's image &lt;code&gt;Accept&lt;/code&gt; header (&lt;code&gt;image/avif,image/webp,image/apng,image/*,*/*;q=0.8&lt;/code&gt;) and once with no &lt;code&gt;Accept&lt;/code&gt; header at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ask the server for the stored size first
&lt;/h2&gt;

&lt;p&gt;Scene7 answers &lt;code&gt;?req=imageprops&lt;/code&gt; with a small text file, and two of its lines are the stored size:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="na"&gt;image.height&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;
&lt;span class="na"&gt;image.width&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The six photos were stored at 1000, 1000, 1001, 2000, 2400 and 2400 px square. &lt;code&gt;?scl=1&lt;/code&gt; returned each one at exactly that size. &lt;code&gt;?wid=3000&amp;amp;hei=3000&lt;/code&gt; returned 3000x3000 for all six, so it enlarged every one of them, including the 1000 px photos. Without any parameter you get a 400 px copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  The format depends on who asks
&lt;/h2&gt;

&lt;p&gt;With Chrome's header, the 1200 px gallery copy came back as AVIF for five of six photos. At &lt;code&gt;scl=1&lt;/code&gt; it was a mix: three AVIF, three JPEG. Without an &lt;code&gt;Accept&lt;/code&gt; header every one of those requests returned JPEG.&lt;/p&gt;

&lt;p&gt;The response tells you why. With Chrome's header, the responses I checked carried an &lt;code&gt;x-adobe-smart-imaging&lt;/code&gt; header, and its value is the JPEG size minus the AVIF size:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Stored size&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;scl=1&lt;/code&gt;, Chrome header&lt;/th&gt;
&lt;th&gt;
&lt;code&gt;scl=1&lt;/code&gt;, no header&lt;/th&gt;
&lt;th&gt;&lt;code&gt;x-adobe-smart-imaging&lt;/code&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2000x2000&lt;/td&gt;
&lt;td&gt;AVIF, 363,238 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 780,995 bytes&lt;/td&gt;
&lt;td&gt;417757&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1000x1000&lt;/td&gt;
&lt;td&gt;AVIF, 16,225 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 50,124 bytes&lt;/td&gt;
&lt;td&gt;33899&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1000x1000&lt;/td&gt;
&lt;td&gt;AVIF, 7,741 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 26,776 bytes&lt;/td&gt;
&lt;td&gt;19035&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1001x1001&lt;/td&gt;
&lt;td&gt;JPEG, 93,714 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 93,714 bytes&lt;/td&gt;
&lt;td&gt;-141024&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2400x2400&lt;/td&gt;
&lt;td&gt;JPEG, 338,223 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 338,223 bytes&lt;/td&gt;
&lt;td&gt;-977451&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2400x2400&lt;/td&gt;
&lt;td&gt;JPEG, 124,540 bytes&lt;/td&gt;
&lt;td&gt;JPEG, 124,540 bytes&lt;/td&gt;
&lt;td&gt;-247638&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;780,995 minus 363,238 is 417,757, and the other two positive rows add up the same way. A negative value means the AVIF would have been bigger, so the server kept the JPEG. Adobe's Smart Imaging docs describe that rule (serve the original when it is smaller than the conversion); the header lets you watch it per request.&lt;/p&gt;

&lt;p&gt;None of the responses had a &lt;code&gt;Vary&lt;/code&gt; header, even though the bytes change with &lt;code&gt;Accept&lt;/code&gt;. If you put your own cache in front of Scene7, key it on &lt;code&gt;Accept&lt;/code&gt; yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;code&gt;fmt&lt;/code&gt; does not win
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;fmt=png&amp;amp;scl=1&lt;/code&gt; with Chrome's header returned AVIF for all six photos. Without the header it returned real PNGs, 87,863 bytes to 4.4 MB. The switch that stops the conversion is &lt;code&gt;bfc=off&lt;/code&gt;: with &lt;code&gt;scl=1&amp;amp;bfc=off&lt;/code&gt;, all six came back as the same JPEG bytes whichever header I sent.&lt;/p&gt;

&lt;p&gt;So the address I use for the stored file is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://target.scene7.com/is/image/Target/&amp;lt;id&amp;gt;?scl=1&amp;amp;bfc=off
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;scl=1&lt;/code&gt; keeps the pixel size honest, and &lt;code&gt;bfc=off&lt;/code&gt; keeps the file the same for every client.&lt;/p&gt;

&lt;p&gt;The steps for doing this by hand, with the results from 29 photos, are in this guide: &lt;a href="https://pixlasso.com/guides/download-target-product-images?src=devto" rel="noopener noreferrer"&gt;https://pixlasso.com/guides/download-target-product-images?src=devto&lt;/a&gt;. I make PixLasso, a browser extension that saves a page's images; it rewrites Target photo addresses to &lt;code&gt;scl=1&lt;/code&gt; and adds &lt;code&gt;bfc=off&lt;/code&gt; for the same reason.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>http</category>
      <category>cdn</category>
    </item>
    <item>
      <title>Substack image URLs: the original file is URL-encoded inside the address</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Fri, 27 Nov 2026 05:47:46 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/substack-image-urls-the-original-file-is-url-encoded-inside-the-address-253i</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/substack-image-urls-the-original-file-is-url-encoded-inside-the-address-253i</guid>
      <description>&lt;p&gt;An image in a Substack post comes from &lt;code&gt;substackcdn.com&lt;/code&gt;, and its address carries two things at once: the transform options and, URL-encoded at the end, the file Substack actually stores.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://substackcdn.com/image/fetch/$s_!JlLK!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F60f1843e-..._2048x1152.png
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The part before the last slash is for the image server. &lt;code&gt;w_1456,c_limit&lt;/code&gt; scales the image down to at most 1456 px wide, &lt;code&gt;f_auto&lt;/code&gt; lets the server pick the format, and &lt;code&gt;q_auto:good&lt;/code&gt; picks the compression. The page's &lt;code&gt;srcset&lt;/code&gt; also lists &lt;code&gt;w_424&lt;/code&gt;, &lt;code&gt;w_848&lt;/code&gt; and &lt;code&gt;w_1272&lt;/code&gt;, each once with &lt;code&gt;f_auto&lt;/code&gt; and once with &lt;code&gt;f_webp&lt;/code&gt;. The part after the slash is an S3 URL, and the numbers at the end of the file name are its pixel size.&lt;/p&gt;

&lt;p&gt;Most post images are also wrapped in a link to the same address without &lt;code&gt;w_1456,c_limit&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four copies of the same image
&lt;/h2&gt;

&lt;p&gt;I took six images from three public posts (Noahpinion, Astral Codex Ten, The Pragmatic Engineer) and fetched each address with curl, once with Chrome's image &lt;code&gt;Accept&lt;/code&gt; header and once without. Here are the two largest uploads:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Address&lt;/th&gt;
&lt;th&gt;PNG, 2048x1152 upload&lt;/th&gt;
&lt;th&gt;PNG, 2360x1338 upload&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;w_848,c_limit,f_webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;848x477, WebP, 86 KB&lt;/td&gt;
&lt;td&gt;848x481, WebP, 16 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;w_1456,c_limit,f_auto&lt;/code&gt; (in the post)&lt;/td&gt;
&lt;td&gt;1456x819, JPEG, 246 KB&lt;/td&gt;
&lt;td&gt;1456x825, JPEG, 62 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;No &lt;code&gt;w_&lt;/code&gt; (the link around the image)&lt;/td&gt;
&lt;td&gt;2048x1152, JPEG, 412 KB&lt;/td&gt;
&lt;td&gt;2360x1338, JPEG, 108 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Decoded S3 URL&lt;/td&gt;
&lt;td&gt;2048x1152, PNG, 5.3 MB&lt;/td&gt;
&lt;td&gt;2360x1338, PNG, 410 KB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Images narrower than 1456 px came back at their own size from the in-post copy, and for all six the link copy was byte for byte the same file as a &lt;code&gt;w_2912&lt;/code&gt; copy I built by hand. Asking for a wider image never enlarges anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  What surprised me
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Accept&lt;/code&gt; header changed nothing. Both requests got identical bytes every time, and &lt;code&gt;f_auto&lt;/code&gt; sent JPEG or PNG even when the request offered AVIF and WebP. The server varied its answer only by &lt;code&gt;Origin&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;f_auto&lt;/code&gt; also turned two of the five PNGs into JPEGs, and the link copy did the same. So "full size" and "original" are two different things here: dropping &lt;code&gt;w_&lt;/code&gt; gets you every pixel, but only the S3 file kept the stored format for all six. Its pixel size matched the numbers in its name every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting the stored file
&lt;/h2&gt;

&lt;p&gt;Take everything after the last &lt;code&gt;/&lt;/code&gt;, decode it, and request that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;img&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currentSrc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;original&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;decodeURIComponent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lastIndexOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'/'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// https://substack-post-media.s3.amazonaws.com/public/images/..._2048x1152.png&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the decoded value does not start with &lt;code&gt;https://substack-post-media.s3.amazonaws.com/&lt;/code&gt;, the image came from somewhere else (an embed, a sponsor banner) and the trick does not apply.&lt;/p&gt;

&lt;p&gt;I keep a list of these URL edits for about 50 sites at &lt;a href="https://github.com/aboivz/fullsize-image-urls" rel="noopener noreferrer"&gt;https://github.com/aboivz/fullsize-image-urls&lt;/a&gt;, and the steps for doing it by hand are here: &lt;a href="https://pixlasso.com/guides/download-images-from-substack?src=devto" rel="noopener noreferrer"&gt;https://pixlasso.com/guides/download-images-from-substack?src=devto&lt;/a&gt;. I make PixLasso, a browser extension that saves a page's images; it has no Substack rule yet, so it saves the link copy, not the S3 file.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>http</category>
      <category>cdn</category>
    </item>
    <item>
      <title>Finding a site's brand color from the console, and why painted area points the wrong way</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Tue, 24 Nov 2026 05:45:16 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/finding-a-sites-brand-color-from-the-console-and-why-painted-area-points-the-wrong-way-4404</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/finding-a-sites-brand-color-from-the-console-and-why-painted-area-points-the-wrong-way-4404</guid>
      <description>&lt;p&gt;If you want to match a site's look, the first color you need is its brand color: the one on the main button, the links, the logo. Finding it by eye is usually easy. Finding it with code is where I went wrong twice, so here is what I measured on three fictional demo sites I built (Northwind Roasters, a coffee shop; Ledgerline, fintech; Afterhours, a dark developer tool) and the snippet I ended up with.&lt;/p&gt;

&lt;h2&gt;
  
  
  The obvious approach, and what it got wrong
&lt;/h2&gt;

&lt;p&gt;My first try summed up the area of every element with an opaque &lt;code&gt;background-color&lt;/code&gt;, grouped by color. On Northwind it said the top color was &lt;code&gt;#f6eadb&lt;/code&gt; at 49%, then white at 45%. On Afterhours, &lt;code&gt;#17141f&lt;/code&gt; at 97%.&lt;/p&gt;

&lt;p&gt;Both are wrong, for two reasons:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Nested boxes count twice.&lt;/strong&gt; A card inside a section inside a wrapper adds its area three times if all three have a background. The totals mean nothing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The page background was missing.&lt;/strong&gt; I looped over &lt;code&gt;document.body.querySelectorAll('*')&lt;/code&gt;, which skips &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;html&amp;gt;&lt;/code&gt;, and that's where most sites set the page color. Northwind's real background, &lt;code&gt;#fffaf3&lt;/code&gt;, didn't even make the top three.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Sampling what is actually painted
&lt;/h2&gt;

&lt;p&gt;The fix is to ask the browser what's on top at each point, then walk up to the first ancestor that paints a background. The snippet scrolls through the page one screen at a time and samples a grid every 16px:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;brandColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;step&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;lin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;0.04045&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;12.92&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.055&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.055&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mf"&gt;2.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;chroma&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// OKLCH chroma&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;lin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.4122214708&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.5363325363&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.0514459929&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2119034982&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.6806995451&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.1073969566&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0883024619&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2817188376&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.6299787005&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hypot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;1.9779984951&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;2.428592205&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.4505937099&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="mf"&gt;0.0259040371&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.7827717662&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;0.808675766&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rgb&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;\&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;\&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;hex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'#'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;padStart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'0'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;paintedBg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// first ancestor with an opaque background&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parentElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the canvas default&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;seen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;clicks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;add&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;documentElement&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;scrollHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;scrollTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;requestAnimationFrame&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;innerHeight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;py&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;px&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;px&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;innerWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;px&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;step&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;elementFromPoint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;paintedBg&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nf"&gt;scrollTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a, button, [role=button]'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getClientRects&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backgroundColor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;color&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;chroma&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.05&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// skip greys&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;top&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Painted background:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;top&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="sb"&gt;`${h} ${(100 * n / total).toFixed(1)}%`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Saturated colors on links and buttons:'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;top&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;clicks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="sb"&gt;`${h} x${n}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;', '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;brandColor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second loop is the part that finds the brand color: it collects the background and text colors of links and buttons, keeping only saturated ones (OKLCH chroma above 0.05, so greys, black and white drop out).&lt;/p&gt;

&lt;h2&gt;
  
  
  What it found
&lt;/h2&gt;

&lt;p&gt;At 1280px wide:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Site&lt;/th&gt;
&lt;th&gt;Painted background (share of samples)&lt;/th&gt;
&lt;th&gt;Saturated colors on links and buttons&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Northwind&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#fffaf3&lt;/code&gt; 64.1%, &lt;code&gt;#ffffff&lt;/code&gt; 21.4%, &lt;code&gt;#f6eadb&lt;/code&gt; 12.0%, &lt;code&gt;#c2410c&lt;/code&gt; 1.5%&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#c2410c&lt;/code&gt; ×3, &lt;code&gt;#4d7c5a&lt;/code&gt; ×1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ledgerline&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#ffffff&lt;/code&gt; 87.7%, &lt;code&gt;#f1f5f9&lt;/code&gt; 10.9%, &lt;code&gt;#1d4ed8&lt;/code&gt; 1.0%, &lt;code&gt;#ecfccb&lt;/code&gt; 0.4%&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#1d4ed8&lt;/code&gt; ×2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Afterhours&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#0c0a14&lt;/code&gt; 75.9%, &lt;code&gt;#17141f&lt;/code&gt; 23.5%, &lt;code&gt;#8b5cf6&lt;/code&gt; 0.5%&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;#8b5cf6&lt;/code&gt; ×1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;At 390px the shares move a little (the brand color goes up to 2.1% on Northwind and 1.5% on Afterhours, because buttons take more of a narrow screen) and the clickable colors are the same.&lt;/p&gt;

&lt;p&gt;Three things stand out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The brand color is a tiny share of the paint.&lt;/strong&gt; 0.5% to 2.1% across the three sites. Any approach that ranks colors by how much of the page they cover will put it fourth or lower, behind the background and surfaces.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The painted ranking is still useful, just for different roles.&lt;/strong&gt; First is the page background, second the surface (cards, panels, alternating sections). That matches how I built the sites.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clickable elements name the brand color every time.&lt;/strong&gt; On all three, the most common saturated color on links and buttons is the one I chose as primary. On Northwind the second one, the sage green &lt;code&gt;#4d7c5a&lt;/code&gt;, is the accent.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Where this will fail
&lt;/h2&gt;

&lt;p&gt;My demo pages have only a few buttons each, so the counts are small. On real sites, check these before you trust the result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Default link blue.&lt;/strong&gt; A site that never styled its links will show &lt;code&gt;#0000ee&lt;/code&gt; as a clickable color. If it shows up, ignore it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Image buttons and gradients.&lt;/strong&gt; A button painted with a background image or gradient has a transparent &lt;code&gt;background-color&lt;/code&gt;, so the snippet only sees its text color.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Accent colors that aren't clickable.&lt;/strong&gt; Ledgerline's lime accent &lt;code&gt;#65a30d&lt;/code&gt; is used for small highlights, not links, so it doesn't appear in the clickable list. The &lt;code&gt;#ecfccb&lt;/code&gt; in its painted list is a pale tint of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a quick answer the snippet is enough: first painted color is the background, second is the surface, top clickable saturated color is the brand.&lt;/p&gt;

&lt;p&gt;I made a Chrome extension, Stylasso, that does this kind of role guessing for the whole palette (plus fonts and spacing) and exports it as CSS variables or a Tailwind theme; the guide is here: &lt;a href="https://stylasso.pixlasso.com/extract-colors-from-website?src=devto" rel="noopener noreferrer"&gt;extract the colors from any website, with roles&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written with help from an AI assistant. Every number comes from running the snippet on the three demo pages in headless Chromium.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Walmart's image server tells you how big the original was</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Tue, 24 Nov 2026 05:44:25 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/walmarts-image-server-tells-you-how-big-the-original-was-5eig</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/walmarts-image-server-tells-you-how-big-the-original-was-5eig</guid>
      <description>&lt;p&gt;Walmart product photos come from &lt;code&gt;i5.walmartimages.com&lt;/code&gt;, and every thumbnail URL carries its size in the query string:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://i5.walmartimages.com/seo/&amp;lt;product-name&amp;gt;_&amp;lt;uuid&amp;gt;.&amp;lt;hash&amp;gt;.jpeg?odnHeight=180&amp;amp;odnWidth=180&amp;amp;odnBg=FFFFFF
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;odnHeight&lt;/code&gt; and &lt;code&gt;odnWidth&lt;/code&gt; set the box, &lt;code&gt;odnBg&lt;/code&gt; fills the padding when the photo is not square. The obvious way to get the full photo is to delete all three. That gives you the full pixel size, but it is not the file the seller uploaded.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the bare URL returns
&lt;/h2&gt;

&lt;p&gt;I took 32 product images and fetched each one twice with Chrome's &lt;code&gt;Accept&lt;/code&gt; header (&lt;code&gt;image/avif,image/webp,image/apng,image/*,*/*;q=0.8&lt;/code&gt;): once with no &lt;code&gt;odn&lt;/code&gt; parameters, once with both set to 4000.&lt;/p&gt;

&lt;p&gt;The bare URL comes back as &lt;code&gt;content-type: image/avif&lt;/code&gt; at the full pixel size, and with two extra headers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tb&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;optimization&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;295370&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;tb&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;optimization&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;original&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;image&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;jpeg&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server is telling you the size and type of the file it started from. The AVIF it sent was 102,815 bytes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Asking for a box bigger than the photo
&lt;/h2&gt;

&lt;p&gt;With &lt;code&gt;?odnHeight=4000&amp;amp;odnWidth=4000&amp;amp;odnBg=FFFFFF&lt;/code&gt; the same image came back as &lt;code&gt;image/jpeg&lt;/code&gt;, 295,370 bytes, the number in that header. It held on every image where the header was present:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Pixels&lt;/th&gt;
&lt;th&gt;Bare URL (AVIF)&lt;/th&gt;
&lt;th&gt;4000 box (JPEG)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1600x1600&lt;/td&gt;
&lt;td&gt;38,113&lt;/td&gt;
&lt;td&gt;115,876&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2000x1500&lt;/td&gt;
&lt;td&gt;294,727&lt;/td&gt;
&lt;td&gt;785,115&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2200x2200&lt;/td&gt;
&lt;td&gt;247,970&lt;/td&gt;
&lt;td&gt;862,692&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3756x3805&lt;/td&gt;
&lt;td&gt;383,819&lt;/td&gt;
&lt;td&gt;775,374&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3300x3300&lt;/td&gt;
&lt;td&gt;38,909&lt;/td&gt;
&lt;td&gt;2,193,025&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The pixel size never changed. On one image I tried 6000, 8000, 10000 and 20000: same 115,876 bytes, same 1600x1600. The server does not upscale, so a box larger than the photo means "send what you have". The largest photo in my sample was 3805 pixels tall, so I can't say what happens to an upload above 4000.&lt;/p&gt;

&lt;p&gt;In two of the 32 the header was missing, and both requests returned identical bytes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the bare URL is smaller
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;Accept&lt;/code&gt; header is doing it. Walmart's CDN re-encodes to AVIF when the browser says it can take AVIF, and it does that whenever it resizes or reformats. A box bigger than the photo seems to skip that path and hand back the stored JPEG. None of this is documented, so treat it as an observation from November 2026, not an API.&lt;/p&gt;

&lt;p&gt;If you are writing a scraper or a downloader, the header is the useful part: compare &lt;code&gt;content-length&lt;/code&gt; with &lt;code&gt;x-tb-optimization-original-content-size&lt;/code&gt; and you know whether you got the original.&lt;/p&gt;

&lt;p&gt;I keep a list of these URL edits for about 50 sites at &lt;a href="https://github.com/aboivz/fullsize-image-urls" rel="noopener noreferrer"&gt;https://github.com/aboivz/fullsize-image-urls&lt;/a&gt;, and the Walmart steps for doing it by hand are here: &lt;a href="https://pixlasso.com/guides/download-walmart-product-images?src=devto" rel="noopener noreferrer"&gt;https://pixlasso.com/guides/download-walmart-product-images?src=devto&lt;/a&gt;. I make PixLasso, a browser extension that applies these rules when it saves a page's images.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>http</category>
      <category>performance</category>
    </item>
    <item>
      <title>Reading a site's spacing scale from computed styles, and the numbers that mislead</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Sun, 22 Nov 2026 11:13:02 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/reading-a-sites-spacing-scale-from-computed-styles-and-the-numbers-that-mislead-1l4g</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/reading-a-sites-spacing-scale-from-computed-styles-and-the-numbers-that-mislead-1l4g</guid>
      <description>&lt;p&gt;When you rebuild a site's look in Tailwind or a design system, colors and fonts are easy to read off the page. Spacing is harder. Nobody hands you "the scale"; you get hundreds of padding, margin and gap values, and you have to guess which ones are tokens and which are one-offs.&lt;/p&gt;

&lt;p&gt;So I wrote a console snippet that counts what the page actually renders, and ran it on three fictional demo sites I built: Northwind Roasters (a coffee shop), Ledgerline (fintech) and Afterhours (a dark developer tool). Here's the snippet, the results, and the three things that made my first version wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The snippet
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;spacingScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Horizontal margins are left out: `margin: 0 auto` and flex `margin-left: auto`&lt;/span&gt;
  &lt;span class="c1"&gt;// compute to whatever space is left over, not to a spacing token.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;props&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'padding-top'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'padding-right'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'padding-bottom'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'padding-left'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'margin-top'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'margin-bottom'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'row-gap'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'column-gap'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'*'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getBoundingClientRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;continue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// hidden elements don't count&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getComputedStyle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parseFloat&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getPropertyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// one vote per value per element&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;counts&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;votes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;onGrid&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;k&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;votes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;table&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fromEntries&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sb"&gt;`${v}px`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;votes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;onGrid4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`${onGrid(4)}%`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;onGrid8&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`${onGrid(8)}%`&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nf"&gt;spacingScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Paste it into the DevTools console on any page. It prints a table of values with how many elements use each, and the share of those uses that sit on a 4px or 8px grid.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it found
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Site&lt;/th&gt;
&lt;th&gt;Values (px × elements)&lt;/th&gt;
&lt;th&gt;On a 4px grid&lt;/th&gt;
&lt;th&gt;On an 8px grid&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Northwind&lt;/td&gt;
&lt;td&gt;2×1, 4×4, 6×4, 10×1, 11×4, 12×7, 16×8, 18×5, 20×5, 24×5, 28×1, 32×2, 48×1, 56×5, 72×2&lt;/td&gt;
&lt;td&gt;73%&lt;/td&gt;
&lt;td&gt;42%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ledgerline&lt;/td&gt;
&lt;td&gt;2×3, 4×3, 8×6, 9×1, 10×5, 12×1, 14×7, 16×2, 18×5, 20×1, 22×7, 28×2, 56×5, 72×1, 80×1&lt;/td&gt;
&lt;td&gt;44%&lt;/td&gt;
&lt;td&gt;30%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Afterhours&lt;/td&gt;
&lt;td&gt;4×3, 8×3, 10×1, 11×3, 16×2, 18×3, 20×4, 22×2, 24×3, 28×2, 40×1, 56×4, 64×1, 72×1, 88×1&lt;/td&gt;
&lt;td&gt;74%&lt;/td&gt;
&lt;td&gt;47%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The results were the same at 1280px and 390px wide, because these demo pages don't change their padding at that width. A real responsive site will give you two different tables, and both are part of its scale.&lt;/p&gt;

&lt;p&gt;All three use the same section padding, 56px, and none of them is a clean 8px system. Northwind and Afterhours are mostly 4px-based with a few odd values (6, 10, 11, 18). Ledgerline has no grid at all: its most common values are 14px and 22px.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three things that skewed the first version
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Auto margins look like huge tokens.&lt;/strong&gt; My first run counted all four margins. Northwind came back with a 577px value, Ledgerline 542px, Afterhours 680px. Those are &lt;code&gt;margin-left: auto&lt;/code&gt; in the nav and &lt;code&gt;margin: 0 auto&lt;/code&gt; on centered containers: &lt;code&gt;getComputedStyle&lt;/code&gt; reports the leftover space in pixels, not the word &lt;code&gt;auto&lt;/code&gt;. At 390px wide those values disappeared, which is the giveaway. Leaving horizontal margins out removes them. You lose real horizontal margins too, so check those by hand if a layout depends on them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Repeated components outvote everything.&lt;/strong&gt; Counting every side of every element, Ledgerline's 22px came out at 26 uses, more than twice the next value. The CSS uses 22px in only three rules (two paddings and one gap); the cards with that padding just repeat on the page, and each card votes four times, once per side. Counting each value once per element brought it down to 7, level with 14px. Neither count is "right", but per-element votes are closer to how often a designer chose that value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Some sites have no grid, and that's a finding.&lt;/strong&gt; It's tempting to snap everything to 4px or 8px. Ledgerline is 44% on a 4px grid, so snapping would move more than half its spacing. If you're matching that site, keep the odd values. In Tailwind v4 that means &lt;code&gt;p-[22px]&lt;/code&gt; where you need the exact value, or deciding on purpose to round to &lt;code&gt;p-5&lt;/code&gt; (20px) or &lt;code&gt;p-6&lt;/code&gt; (24px) and accepting the change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Turning the table into tokens
&lt;/h2&gt;

&lt;p&gt;What I do with the output:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Drop values used once unless they're structural (section padding, page gutters).&lt;/li&gt;
&lt;li&gt;Keep the rest as the scale, in order. For Northwind that's 4, 6, 11, 12, 16, 18, 20, 24, 32, 56, 72.&lt;/li&gt;
&lt;li&gt;Check the grid share. Above roughly 70% on 4px, round the stragglers and note it. Below that, keep the exact values.&lt;/li&gt;
&lt;li&gt;Compare the 1280px and 390px tables to see which values are swapped on mobile.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The snippet only sees the page you're on. Run it on two or three page types (home, a content page, a form) before calling it the site's scale.&lt;/p&gt;

&lt;p&gt;I made a Chrome extension, Stylasso, that reads spacing from the same properties (it leaves out side margins too, though it counts each side rather than one vote per element) along with colors, fonts and radii, and writes it out as CSS variables or a Tailwind v4 theme; there's a guide here: &lt;a href="https://stylasso.pixlasso.com/website-to-tailwind-theme?src=devto" rel="noopener noreferrer"&gt;turn any website into a Tailwind v4 theme&lt;/a&gt;. The snippet above is enough if spacing is all you need.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written with help from an AI assistant. Every number comes from running the snippet on the three demo pages in headless Chromium.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>design</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Etsy image URLs: the size token takes any width, and the .jpg is WebP in Chrome</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Fri, 20 Nov 2026 05:49:16 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/etsy-image-urls-the-size-token-takes-any-width-and-the-jpg-is-webp-in-chrome-c6o</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/etsy-image-urls-the-size-token-takes-any-width-and-the-jpg-is-webp-in-chrome-c6o</guid>
      <description>&lt;p&gt;An Etsy listing photo has an address shaped like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://i.etsystatic.com/&amp;lt;shop&amp;gt;/r/il/&amp;lt;hash&amp;gt;/&amp;lt;id&amp;gt;/il_794xN.&amp;lt;id&amp;gt;_&amp;lt;suffix&amp;gt;.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Today (20 November 2026) I fetched one listing photo from &lt;code&gt;i.etsystatic.com&lt;/code&gt; with curl in 31 variants to see which parts of that address the CDN reads. The photo is stored at 2947×3000. All sizes below are for that one image, so your byte counts will differ, but the rules should carry over.&lt;/p&gt;

&lt;h2&gt;
  
  
  The size token takes any width
&lt;/h2&gt;

&lt;p&gt;With no &lt;code&gt;Accept&lt;/code&gt; header, every request came back as JPEG:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Token&lt;/th&gt;
&lt;th&gt;Pixels&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_75x75&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;75×75&lt;/td&gt;
&lt;td&gt;2,222&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_170x135&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;170×135&lt;/td&gt;
&lt;td&gt;5,928&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_300x300&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;300×300&lt;/td&gt;
&lt;td&gt;15,193&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_340x270&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;340×270&lt;/td&gt;
&lt;td&gt;16,395&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_570xN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;570×580&lt;/td&gt;
&lt;td&gt;39,151&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_794xN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;794×808&lt;/td&gt;
&lt;td&gt;65,007&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_1140xN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1140×1161&lt;/td&gt;
&lt;td&gt;118,966&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_1588xN&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;1588×1617&lt;/td&gt;
&lt;td&gt;244,040&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;il_fullxfull&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;2947×3000&lt;/td&gt;
&lt;td&gt;1,164,396&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;WxN&lt;/code&gt; fits the width and lets the height follow the photo's proportions. &lt;code&gt;WxH&lt;/code&gt; crops to exactly that box, which is why the 340×270 thumbnail of a nearly square photo loses its top and bottom.&lt;/p&gt;

&lt;p&gt;Then I tried widths I made up. &lt;code&gt;il_1000xN&lt;/code&gt; returned 1000×1018 (94,450 bytes), &lt;code&gt;il_2000xN&lt;/code&gt; returned 2000×2036 (445,416 bytes), and &lt;code&gt;il_600x600&lt;/code&gt; returned a 600×600 crop (42,106 bytes). So the token is a resize instruction the server parses, and you can ask for the width your layout needs.&lt;/p&gt;

&lt;h2&gt;
  
  
  fullxfull is the ceiling, and bigger numbers upscale
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;il_fullxfull&lt;/code&gt; returned 2947×3000. &lt;code&gt;il_NxN&lt;/code&gt; returned the same file, byte for byte.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;il_5000xN&lt;/code&gt; returned a 5000×5090 JPEG of 2,671,221 bytes. That is the same photo stretched: more than twice the bytes and no extra detail. If you are collecting originals, rewrite to &lt;code&gt;il_fullxfull&lt;/code&gt; and leave the big numbers alone.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;full&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$1"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; sed -E &lt;span class="s1"&gt;'s#/il_[0-9A-Za-z]+x[0-9A-Za-z]+\.#/il_fullxfull.#'&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The .jpg is WebP when the client lists WebP
&lt;/h2&gt;

&lt;p&gt;The address always ends in &lt;code&gt;.jpg&lt;/code&gt;. What comes back depends on the &lt;code&gt;Accept&lt;/code&gt; header:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Accept&lt;/th&gt;
&lt;th&gt;794xN&lt;/th&gt;
&lt;th&gt;fullxfull&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;none, &lt;code&gt;*/*&lt;/code&gt; or &lt;code&gt;image/jpeg&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;image/jpeg, 65,007&lt;/td&gt;
&lt;td&gt;image/jpeg, 1,164,396&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp, 37,524&lt;/td&gt;
&lt;td&gt;image/webp, 903,692&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chrome's image header (&lt;code&gt;image/avif,image/webp,...&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;image/webp, 37,524&lt;/td&gt;
&lt;td&gt;image/webp, 903,692&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;image/avif&lt;/code&gt; only&lt;/td&gt;
&lt;td&gt;image/jpeg, 65,007&lt;/td&gt;
&lt;td&gt;image/jpeg, 1,164,396&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;WebP is 42% smaller at 794 px and 22% smaller at full size. I never got AVIF, even when it was the only modern format in the header.&lt;/p&gt;

&lt;p&gt;The response carries &lt;code&gt;vary: Accept&lt;/code&gt;, comes through Fastly, and is cached with &lt;code&gt;cache-control: public, max-age=365000000, immutable&lt;/code&gt;, which is about 11.6 years.&lt;/p&gt;

&lt;p&gt;This explains a common complaint. Open the full-size photo in a Chrome tab, choose "Save image as", and you get a &lt;code&gt;.webp&lt;/code&gt;, because a tab navigation sends an Accept header that lists &lt;code&gt;image/webp&lt;/code&gt;. &lt;code&gt;fetch()&lt;/code&gt; sends &lt;code&gt;*/*&lt;/code&gt; unless you set the header yourself, so a script that fetches the same address gets the JPEG.&lt;/p&gt;

&lt;h2&gt;
  
  
  You cannot change the extension
&lt;/h2&gt;

&lt;p&gt;Swapping &lt;code&gt;.jpg&lt;/code&gt; for &lt;code&gt;.webp&lt;/code&gt;, &lt;code&gt;.png&lt;/code&gt; or &lt;code&gt;.avif&lt;/code&gt; returned HTTP 404 each time. The body of that 404 is a 49-byte, 10×10 GIF with &lt;code&gt;content-type: image/gif&lt;/code&gt;. A downloader that only checks "did an image come back" will happily save it, so check the status code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The /r/ segment made no difference
&lt;/h2&gt;

&lt;p&gt;I removed &lt;code&gt;/r/&lt;/code&gt; from the path, then replaced it with &lt;code&gt;/c/&lt;/code&gt;. Both returned the same 65,007-byte file as the original address. I don't know what Etsy uses the segment for; for this photo the CDN ignored it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking a photo yourself
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8'&lt;/span&gt;
&lt;span class="nv"&gt;u&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'&amp;lt;an il_794xN address copied from a listing&amp;gt;'&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; h &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s1"&gt;'*/*'&lt;/span&gt; &lt;span class="s2"&gt;"$A"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  curl -s -H &lt;span class="s2"&gt;"Accept: $h"&lt;/span&gt; -o /dev/null \
    -w &lt;span class="s2"&gt;"%{http_code} %{content_type} %{size_download}\n"&lt;/span&gt; &lt;span class="s2"&gt;"$(full "&lt;/span&gt;&lt;span class="nv"&gt;$u&lt;/span&gt;&lt;span class="s2"&gt;")"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line is what a script gets and the second is what Chrome gets.&lt;/p&gt;

&lt;p&gt;I build &lt;a href="https://pixlasso.com/?src=devto" rel="noopener noreferrer"&gt;PixLasso&lt;/a&gt;, a Chrome and Edge extension that applies this rewrite when it collects the images on a page, and its free right-click "Save image as JPG" re-encodes the WebP on your machine. The manual steps, with the size table for sellers who want their own listing photos back, are in the &lt;a href="https://pixlasso.com/guides/download-etsy-listing-photos?src=devto" rel="noopener noreferrer"&gt;Etsy listing photos guide&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>http</category>
      <category>ecommerce</category>
    </item>
    <item>
      <title>format=jpg works on Cloudinary and imgix. On Shopify it does nothing</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Tue, 17 Nov 2026 05:48:39 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/formatjpg-works-on-cloudinary-and-imgix-on-shopify-it-does-nothing-okc</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/formatjpg-works-on-cloudinary-and-imgix-on-shopify-it-does-nothing-okc</guid>
      <description>&lt;p&gt;When Chrome saves a &lt;code&gt;.webp&lt;/code&gt; you didn't want, the usual advice is "change &lt;code&gt;format=webp&lt;/code&gt; to &lt;code&gt;jpg&lt;/code&gt; in the address". I tested that on four image CDNs this morning (17 November 2026) with curl, sending the &lt;code&gt;Accept&lt;/code&gt; header Chrome sends for images: &lt;code&gt;image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8&lt;/code&gt;. It works on three of them. Shopify behaves differently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloudinary: the transform segment wins
&lt;/h2&gt;

&lt;p&gt;Demo image &lt;code&gt;res.cloudinary.com/demo/image/upload/&amp;lt;f&amp;gt;/sample.jpg&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Segment&lt;/th&gt;
&lt;th&gt;Content-Type&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;f_auto&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/avif&lt;/td&gt;
&lt;td&gt;38,161&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;f_webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;46,116&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;f_jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;120,253&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;f_png&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/png&lt;/td&gt;
&lt;td&gt;688,611&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;f_auto&lt;/code&gt; reads the Accept header and picks AVIF for Chrome. Any explicit &lt;code&gt;f_&lt;/code&gt; value overrides it. PNG comes out 18 times heavier than the AVIF for the same photo.&lt;/p&gt;

&lt;h2&gt;
  
  
  imgix and Unsplash: &lt;code&gt;fm&lt;/code&gt; wins, &lt;code&gt;auto=format&lt;/code&gt; negotiates
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;assets.imgix.net/hp/snowshoe.jpg?w=1200&lt;/code&gt;:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;Content-Type&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;193,987&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fm=webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;233,612&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;fm=jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;193,998&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;auto=format&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/avif&lt;/td&gt;
&lt;td&gt;155,579&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The WebP here is larger than the JPEG. Unsplash runs on imgix and gave the same pattern: no parameter or &lt;code&gt;fm=jpg&lt;/code&gt; returned a 179,799-byte JPEG, and &lt;code&gt;auto=format&lt;/code&gt; returned a 127,875-byte AVIF. So on these two, an image only turns into WebP or AVIF because the site asked for it in the URL. Delete &lt;code&gt;auto=format&lt;/code&gt; or set &lt;code&gt;fm=jpg&lt;/code&gt; and you get the JPEG.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shopify: &lt;code&gt;format=jpg&lt;/code&gt; does nothing
&lt;/h2&gt;

&lt;p&gt;Shopify's CDN takes a &lt;code&gt;format&lt;/code&gt; parameter too, but on a JPG product photo from Brooklinen (&lt;code&gt;?width=1200&lt;/code&gt;) I got:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Query&lt;/th&gt;
&lt;th&gt;Content-Type&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;none&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;118,350&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;format=jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;118,350&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;format=png&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;118,350&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;format=pjpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;247,490&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Only &lt;code&gt;pjpg&lt;/code&gt; (progressive JPEG) forces a JPEG. On a transparent PNG product image from Allbirds, a test earlier today found that even &lt;code&gt;pjpg&lt;/code&gt; kept returning WebP.&lt;/p&gt;

&lt;p&gt;The Accept header explains the rest. With the same URL and no parameter:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Accept&lt;/th&gt;
&lt;th&gt;Content-Type&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/webp,*/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/avif,*/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Shopify sends WebP only when the browser lists it. It never sent AVIF, even when AVIF was the only modern format listed.&lt;/p&gt;

&lt;h2&gt;
  
  
  A five-line check
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;A&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8'&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; u &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"$@"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  curl -s -H &lt;span class="s2"&gt;"Accept: $A"&lt;/span&gt; -o /dev/null \
    -w &lt;span class="s2"&gt;"%{content_type} %{size_download} $u\n"&lt;/span&gt; &lt;span class="s2"&gt;"$u"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pass it the same image with each parameter variant and you see what Chrome would get before you try saving anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  When there is no parameter
&lt;/h2&gt;

&lt;p&gt;Next.js &lt;code&gt;/_next/image&lt;/code&gt; and WordPress Jetpack (&lt;code&gt;i0.wp.com&lt;/code&gt;) have no format parameter, so they decide from the Accept header alone. There you either convert the saved file locally or use a right-click extension that re-encodes it. I build one, &lt;a href="https://pixlasso.com/?src=devto" rel="noopener noreferrer"&gt;PixLasso&lt;/a&gt;. Its free Save image as JPG fetches the full-size file and redraws it at 92% JPEG quality on your machine. The full table, including the steps for Paint and Preview, is in the &lt;a href="https://pixlasso.com/guides/save-webp-as-jpg-chrome?src=devto" rel="noopener noreferrer"&gt;WebP to JPG guide&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>performance</category>
      <category>cdn</category>
    </item>
    <item>
      <title>Shopee, Lazada and Tiki image URLs: the suffix picks the format, not the Accept header</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Mon, 16 Nov 2026 05:49:37 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/shopee-lazada-and-tiki-image-urls-the-suffix-picks-the-format-not-the-accept-header-3k6g</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/shopee-lazada-and-tiki-image-urls-the-suffix-picks-the-format-not-the-accept-header-3k6g</guid>
      <description>&lt;p&gt;On several image CDNs I tested this month, the same URL returns different bytes depending on the browser's &lt;code&gt;Accept&lt;/code&gt; header. Wix and Dribbble's imgproxy do it and send &lt;code&gt;Vary: Accept&lt;/code&gt; so caches keep the copies apart, and Shopify's CDN switched formats with the header too.&lt;/p&gt;

&lt;p&gt;The three big marketplace CDNs in Southeast Asia don't. On Shopee, Lazada and Tiki the format and the size are both written into the URL, and the server returns the same file whatever the browser says it accepts. I measured this on 16 November 2026 with curl, using product thumbnails taken from a search for "bình giữ nhiệt" (vacuum flask) on each site, and sent every request twice: once with Chrome's image &lt;code&gt;Accept&lt;/code&gt; header and once with &lt;code&gt;*/*&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shopee: &lt;code&gt;@resize_…&lt;/code&gt; and &lt;code&gt;_tn&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;A Shopee search result thumbnail looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://down-vn.img.susercontent.com/file/vn-11134207-81ztc-mu1v1eehy22oef@resize_w320_nl.webp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Suffix&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Size&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@resize_w320_nl.webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;320x320&lt;/td&gt;
&lt;td&gt;22,684&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_tn.webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;320x320&lt;/td&gt;
&lt;td&gt;22,684&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_tn&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;JPEG&lt;/td&gt;
&lt;td&gt;320x320&lt;/td&gt;
&lt;td&gt;38,555&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;@resize_w800_nl.webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;800x800&lt;/td&gt;
&lt;td&gt;75,416&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;.webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;1024x1024&lt;/td&gt;
&lt;td&gt;100,070&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(none)&lt;/td&gt;
&lt;td&gt;JPEG&lt;/td&gt;
&lt;td&gt;1024x1024&lt;/td&gt;
&lt;td&gt;867,216&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So &lt;code&gt;_tn&lt;/code&gt; means thumbnail, &lt;code&gt;@resize_w&amp;lt;N&amp;gt;&lt;/code&gt; picks a width, and a trailing &lt;code&gt;.webp&lt;/code&gt; picks the format. Drop everything after the file ID and you get the uploaded image as JPEG. Note how big that is: the JPEG original is 8.7 times the WebP at the same 1024x1024.&lt;/p&gt;

&lt;p&gt;Both &lt;code&gt;Accept&lt;/code&gt; values gave identical responses on every row, and there was no &lt;code&gt;Vary&lt;/code&gt; header.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lazada: &lt;code&gt;_&amp;lt;W&amp;gt;x&amp;lt;H&amp;gt;q&amp;lt;Q&amp;gt;&lt;/code&gt; plus an optional second extension
&lt;/h2&gt;

&lt;p&gt;Lazada (now &lt;code&gt;img.lazcdn.com&lt;/code&gt;, older pages use &lt;code&gt;slatic.net&lt;/code&gt;) appends the resize instruction to the original file name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://img.lazcdn.com/g/p/c94d7169c793ea7a4590bb06036778e7.jpg_80x80q80.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Suffix&lt;/th&gt;
&lt;th&gt;Type&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_80x80q80.jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;JPEG 80x80&lt;/td&gt;
&lt;td&gt;4,156&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_400x400q80.jpg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;JPEG&lt;/td&gt;
&lt;td&gt;10,162&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_2200x2200q80.jpg_.webp&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;WebP&lt;/td&gt;
&lt;td&gt;11,902&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;_2200x2200q80.jpg_.avif&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;AVIF&lt;/td&gt;
&lt;td&gt;3,209&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;(none)&lt;/td&gt;
&lt;td&gt;JPEG 1000x1000&lt;/td&gt;
&lt;td&gt;126,954&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;_.avif&lt;/code&gt; and &lt;code&gt;_.webp&lt;/code&gt; endings are a second extension tacked on after the JPEG one, and the server converts to whatever it names. Asking for 2200x2200 does not upscale: the original is only 1000x1000.&lt;/p&gt;

&lt;p&gt;Two small surprises. The original JPEG comes back as &lt;code&gt;Content-Type: image/jpg&lt;/code&gt;, which is not a registered type, so code that maps MIME types to file extensions needs an entry for it. And when a seller uploaded a PNG, the original stays a PNG: one product photo was a 1254x1254 PNG of 1,644,982 bytes, against 56,283 bytes for its 200x200 thumbnail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tiki: a &lt;code&gt;/cache/&amp;lt;W&amp;gt;x&amp;lt;H&amp;gt;/&lt;/code&gt; path segment
&lt;/h2&gt;

&lt;p&gt;Tiki puts the size in the path instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://salt.tikicdn.com/cache/280x280/ts/product/59/55/bd/1446d17fc400afa9cb4aa874f254d5c7.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing &lt;code&gt;/cache/280x280&lt;/code&gt; gave an 800x800 JPEG (78,473 bytes) for this product and a 1000x1000 JPEG (111,055 bytes) for a second one under &lt;code&gt;/media/catalog/producttmp/&lt;/code&gt;. Adding &lt;code&gt;.webp&lt;/code&gt; to the end of a cached URL returns WebP, again regardless of &lt;code&gt;Accept&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stripping the suffixes
&lt;/h2&gt;

&lt;p&gt;The rules fit in a few regular expressions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;marketplaceOriginal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;^|&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;susercontent&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nd"&gt;@resize_&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;^/&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;+|&lt;/span&gt;&lt;span class="nf"&gt;_tn&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;webp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?|&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;webp&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;^|&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lazcdn&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;slatic&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;net&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jpe&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;\&lt;span class="n"&gt;w&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;^|&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;tikicdn&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;com&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/^&lt;/span&gt;\&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;\&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;\&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;jpe&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;png&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;\&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;webp&lt;/span&gt;$&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'$1'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;u&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because none of these servers negotiate on &lt;code&gt;Accept&lt;/code&gt;, a URL you rewrite this way returns the same bytes in a script as it does in the browser. That is not true on Wix or Shopify, where a &lt;code&gt;curl&lt;/code&gt; without Chrome's header can hand you a different format than the one you saw on screen.&lt;/p&gt;

&lt;p&gt;One limit worth knowing: the original is only as large as what the seller uploaded. If a shop posted a 500x500 photo, no suffix trick will give you more.&lt;/p&gt;

&lt;p&gt;I use these rules in PixLasso, a Chrome and Edge extension that saves every image on a page (or across open tabs) as originals in one ZIP. The &lt;a href="https://pixlasso.com/guides/download-product-images-shopee-1688-amazon?src=devto" rel="noopener noreferrer"&gt;guide to downloading Shopee, 1688 and Amazon product images&lt;/a&gt; covers the manual steps for more marketplaces, and there is a &lt;a href="https://pixlasso.com/guides/tai-anh-goc-san-pham-1688-shopee-lazada?src=devto" rel="noopener noreferrer"&gt;Vietnamese version with these Shopee, Lazada and Tiki numbers&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>ecommerce</category>
      <category>performance</category>
    </item>
    <item>
      <title>Removing image/webp from the Accept header mostly gets you AVIF: five image hosts tested</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Sun, 15 Nov 2026 05:48:27 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/removing-imagewebp-from-the-accept-header-mostly-gets-you-avif-five-image-hosts-tested-37pn</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/removing-imagewebp-from-the-accept-header-mostly-gets-you-avif-five-image-hosts-tested-37pn</guid>
      <description>&lt;p&gt;People who want JPG files instead of WebP often try an extension that removes &lt;code&gt;image/webp&lt;/code&gt; from the &lt;code&gt;Accept&lt;/code&gt; header Chrome sends with image requests. The idea is that the server will then fall back to JPEG. I tested that on 15 November 2026 against five image hosts, with curl and a Chrome user agent, sending each image request three times:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Chrome's normal header: &lt;code&gt;image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The same with &lt;code&gt;image/webp&lt;/code&gt; removed&lt;/li&gt;
&lt;li&gt;The same with both &lt;code&gt;image/webp&lt;/code&gt; and &lt;code&gt;image/avif&lt;/code&gt; removed&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Results
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Image&lt;/th&gt;
&lt;th&gt;Normal&lt;/th&gt;
&lt;th&gt;No WebP&lt;/th&gt;
&lt;th&gt;No WebP, no AVIF&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Unsplash (imgix, &lt;code&gt;auto=format&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;AVIF, 21,077 B&lt;/td&gt;
&lt;td&gt;AVIF, 21,077 B&lt;/td&gt;
&lt;td&gt;JPEG, 50,606 B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IKEA product photo (Cloudflare)&lt;/td&gt;
&lt;td&gt;AVIF, 19,016 B&lt;/td&gt;
&lt;td&gt;AVIF, 19,016 B&lt;/td&gt;
&lt;td&gt;JPEG, 71,924 B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudinary demo (&lt;code&gt;f_auto&lt;/code&gt;)&lt;/td&gt;
&lt;td&gt;AVIF, 38,161 B&lt;/td&gt;
&lt;td&gt;AVIF, 38,161 B&lt;/td&gt;
&lt;td&gt;JPEG, 87,162 B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Allbirds (Shopify CDN)&lt;/td&gt;
&lt;td&gt;WebP, 46,738 B&lt;/td&gt;
&lt;td&gt;PNG, 118,448 B&lt;/td&gt;
&lt;td&gt;PNG, 118,448 B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Nike (&lt;code&gt;t_default&lt;/code&gt; preset)&lt;/td&gt;
&lt;td&gt;PNG, 147,200 B&lt;/td&gt;
&lt;td&gt;PNG, 147,200 B&lt;/td&gt;
&lt;td&gt;PNG, 147,200 B&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three of the five hosts prefer AVIF over WebP. For them, removing WebP from the list changes nothing, because AVIF is still listed and AVIF is what they were sending anyway. Only the Shopify CDN, which tops out at WebP, falls back to the original PNG once WebP is gone.&lt;/p&gt;

&lt;p&gt;The Nike URL uses a named preset with no format option in it, so the server sends the same PNG to everyone. Its response has no &lt;code&gt;Vary&lt;/code&gt; header at all. The other four answer with &lt;code&gt;Vary: Accept&lt;/code&gt; (Unsplash and Cloudinary also vary on &lt;code&gt;User-Agent&lt;/code&gt;), which is the signal that the format depends on what you ask for.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sending &lt;code&gt;*/*&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;A request with &lt;code&gt;Accept: */*&lt;/code&gt; got the original format from all five: JPEG from Unsplash, IKEA and Cloudinary, PNG from Allbirds and Nike. That is also what curl and wget send by default, which is why a command-line download of an image URL often gives you a JPEG while "Save image as" in the browser gives you WebP or AVIF. The browser saves the bytes it already received for display.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this means in practice
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;An extension that only strips &lt;code&gt;image/webp&lt;/code&gt; mostly trades WebP for AVIF on big image CDNs. Stripping AVIF too gets JPEG where the server negotiates, but pages then load larger files.&lt;/li&gt;
&lt;li&gt;Hosts that pick the format from a fixed URL preset ignore the header completely.&lt;/li&gt;
&lt;li&gt;If you only need one file, the URL is often the easier lever. With Chrome's normal header still sent, imgix returned a real JPEG for &lt;code&gt;fm=jpg&lt;/code&gt; (50,606 B, the same file as the third request above) and Cloudinary for &lt;code&gt;f_jpg&lt;/code&gt; in place of &lt;code&gt;f_auto&lt;/code&gt;. Shopify's CDN did not: &lt;code&gt;format=jpg&lt;/code&gt; and &lt;code&gt;format=pjpg&lt;/code&gt; both still came back as WebP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I make PixLasso, a Chrome and Edge extension that converts on right-click instead (it draws the image and saves a real JPG or PNG locally), so I had a reason to check whether header tricks would make that unnecessary. On these five hosts they mostly don't. The guide with the other no-install options, Firefox's &lt;code&gt;image.http.accept&lt;/code&gt; pref included, is here: &lt;a href="https://pixlasso.com/guides/chrome-disable-webp?src=devto" rel="noopener noreferrer"&gt;Can you disable WebP in Chrome?&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>images</category>
      <category>http</category>
      <category>chrome</category>
    </item>
    <item>
      <title>Stop the jump when a web font loads, measured with three Google fonts</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Sun, 15 Nov 2026 04:47:56 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/stop-the-jump-when-a-web-font-loads-measured-with-three-google-fonts-2pa</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/stop-the-jump-when-a-web-font-loads-measured-with-three-google-fonts-2pa</guid>
      <description>&lt;p&gt;With &lt;code&gt;font-display: swap&lt;/code&gt;, the browser shows text in a fallback font first and swaps in the web font when it arrives. If the two fonts take up different space, the text reflows and everything below it moves. CSS has four descriptors to make a local fallback font take up the same space: &lt;code&gt;size-adjust&lt;/code&gt;, &lt;code&gt;ascent-override&lt;/code&gt;, &lt;code&gt;descent-override&lt;/code&gt; and &lt;code&gt;line-gap-override&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I wanted to know how big the jump really is for the fonts I use on demo sites, and whether the fix works, so I measured it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;One paragraph of 250 characters at 17px, set in three Google fonts: Hanken Grotesk, Manrope and Space Grotesk. The fallback is Arial. I ran this in headless Chromium on Linux, where Arial isn't installed, so I used Liberation Sans, which was made to have the same metrics as Arial.&lt;/p&gt;

&lt;p&gt;Two column widths: 343px (a phone with 16px margins) and 560px. Two line heights: &lt;code&gt;1.6&lt;/code&gt; and &lt;code&gt;normal&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How far the text moves with a plain fallback
&lt;/h2&gt;

&lt;p&gt;Paragraph height, real font vs. plain fallback:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Font&lt;/th&gt;
&lt;th&gt;343px, &lt;code&gt;line-height: 1.6&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;343px, &lt;code&gt;normal&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;560px, &lt;code&gt;1.6&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;560px, &lt;code&gt;normal&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hanken Grotesk&lt;/td&gt;
&lt;td&gt;163.1 vs 163.1&lt;/td&gt;
&lt;td&gt;132 vs 120&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;88 vs 80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Manrope&lt;/td&gt;
&lt;td&gt;163.1 vs 163.1&lt;/td&gt;
&lt;td&gt;138 vs 120&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;92 vs 80&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Grotesk&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;190.3 vs 163.1&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;154 vs 120&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;88 vs 80&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two different things are going on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With &lt;code&gt;line-height: normal&lt;/code&gt;, every font shifts&lt;/strong&gt;, even when the line breaks are identical. "Normal" means "use the font's own ascent, descent and line gap", and those differ: Manrope's ascent and descent add up to 1.37 times the font size; Arial's ascent and descent are 1.12, about 1.15 with its line gap. So every line grows when Manrope arrives. Here that's 12 to 18px for one paragraph, more on a page of them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With a fixed &lt;code&gt;line-height: 1.6&lt;/code&gt;, only the line count matters.&lt;/strong&gt; Each line is 27.2px whatever the font, so Hanken and Manrope don't move the paragraph at all. Space Grotesk does: it's about 8% wider than Arial, so at 343px the text needs 7 lines instead of 6 and the paragraph grows by one line, 27.2px.&lt;/p&gt;

&lt;p&gt;So the first fix is free: set a unitless line height on body text. That removes the line-box part of the shift for every font; what's left comes from line breaks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing the fallback @font-face
&lt;/h2&gt;

&lt;p&gt;For the width, &lt;code&gt;size-adjust&lt;/code&gt; scales the fallback's glyphs. For the line box, the three overrides set the ascent, descent and line gap the fallback should report. Both can be measured in the console once the web font has loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fallbackFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;family&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;localName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fonts&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`100px "${family}"`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sample&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Small-batch beans roasted every Tuesday in our Portland shop, shipped the same week so they reach you while the flavor is still bright.'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'canvas'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'2d'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;measure&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;font&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`100px ${font}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measureText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;web&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`"${family}"`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;measure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sb"&gt;`"${localName}"`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;sizeAdjust&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;web&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;width&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;'%'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`@font-face {
  font-family: "${family} Fallback";
  src: local("${localName}");
  size-adjust: ${pct(sizeAdjust)};
  ascent-override: ${pct(web.fontBoundingBoxAscent / 100 / sizeAdjust)};
  descent-override: ${pct(web.fontBoundingBoxDescent / 100 / sizeAdjust)};
  line-gap-override: 0%;
}`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The overrides are divided by &lt;code&gt;sizeAdjust&lt;/code&gt;. They're percentages of the font size, and the font size of the fallback is already scaled by &lt;code&gt;size-adjust&lt;/code&gt;, so without the division the line box comes out too tall by the same factor.&lt;/li&gt;
&lt;li&gt;The width ratio comes from a real sentence, not the alphabet. Letter frequency matters: a font with a wide "m" and narrow "i" averages differently on prose than on "abcdefghijklmnopqrstuvwxyz".&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What it printed (with &lt;code&gt;'Liberation Sans'&lt;/code&gt; as the local name):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Font&lt;/th&gt;
&lt;th&gt;size-adjust&lt;/th&gt;
&lt;th&gt;ascent-override&lt;/th&gt;
&lt;th&gt;descent-override&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hanken Grotesk&lt;/td&gt;
&lt;td&gt;100.8%&lt;/td&gt;
&lt;td&gt;99.2%&lt;/td&gt;
&lt;td&gt;29.7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Manrope&lt;/td&gt;
&lt;td&gt;102.4%&lt;/td&gt;
&lt;td&gt;104.5%&lt;/td&gt;
&lt;td&gt;29.3%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Grotesk&lt;/td&gt;
&lt;td&gt;109.3%&lt;/td&gt;
&lt;td&gt;89.6%&lt;/td&gt;
&lt;td&gt;26.5%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Then use the fallback right after the web font:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Space Grotesk"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Space Grotesk Fallback"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  After
&lt;/h2&gt;

&lt;p&gt;Same paragraph, real font vs. adjusted fallback:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Font&lt;/th&gt;
&lt;th&gt;343px, &lt;code&gt;1.6&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;343px, &lt;code&gt;normal&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;560px, &lt;code&gt;1.6&lt;/code&gt;
&lt;/th&gt;
&lt;th&gt;560px, &lt;code&gt;normal&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Hanken Grotesk&lt;/td&gt;
&lt;td&gt;163.1 vs 163.1&lt;/td&gt;
&lt;td&gt;132 vs 132&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;88 vs 88&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Manrope&lt;/td&gt;
&lt;td&gt;163.1 vs 163.1&lt;/td&gt;
&lt;td&gt;138 vs 138&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;92 vs 92&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Space Grotesk&lt;/td&gt;
&lt;td&gt;190.3 vs 190.3&lt;/td&gt;
&lt;td&gt;154 vs 154&lt;/td&gt;
&lt;td&gt;108.8 vs 108.8&lt;/td&gt;
&lt;td&gt;88 vs 88&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Every height matches, including &lt;code&gt;line-height: normal&lt;/code&gt;, and Space Grotesk's fallback now wraps to 7 lines like the real font.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it doesn't fix
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Widths only match on average.&lt;/strong&gt; At 100px, the adjusted fallback for Space Grotesk set my test paragraph on one line within 0.5% of the real font's width (12213px vs 12157px). At 17px, on this Linux machine, it came out 6% wider (2163px vs 2038px on one line), while the plain fallback was 7% narrower. I suspect font hinting rounding each glyph's width to whole pixels at small sizes, but I didn't dig into it. Line breaks matched for my paragraph; a different paragraph can still break on a different word. The fix makes a reflow much smaller and much rarer, not impossible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The local font has to exist.&lt;/strong&gt; &lt;code&gt;local("Arial")&lt;/code&gt; matches nothing on a machine without Arial; then the fallback face is skipped and the next font in the stack is used, unadjusted. Mac and Windows ship Arial. Many Linux systems don't, but often have Liberation Sans, so &lt;code&gt;src: local("Arial"), local("Liberation Sans");&lt;/code&gt; covers both with the same numbers. A system with only DejaVu Sans would need its own fallback face.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Headings need their own check.&lt;/strong&gt; A display serif against Georgia or Times needs a separate fallback face and separate numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short version
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Use a unitless line height for body text. That alone removed the vertical shift for two of the three fonts.&lt;/li&gt;
&lt;li&gt;For the rest, generate a fallback &lt;code&gt;@font-face&lt;/code&gt; with &lt;code&gt;size-adjust&lt;/code&gt; and the three overrides, measured on real text, with the overrides divided by &lt;code&gt;size-adjust&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Measure the result: paragraph heights at a phone width and a desktop width, real font vs. fallback.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you're doing this for a site you didn't build, you first need to know which fonts it renders and which weights. I made a Chrome extension, Stylasso, that lists the fonts a page actually renders (up to six), with their role, weights and where it loads from; there's a guide here: &lt;a href="https://stylasso.pixlasso.com/what-font-is-this-website-using?src=devto" rel="noopener noreferrer"&gt;what font is this website using&lt;/a&gt;. DevTools' Rendered Fonts gives you the same for one element at a time.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written with help from an AI assistant. Every number comes from running the snippet and layout tests described above in headless Chromium.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>typography</category>
      <category>performance</category>
    </item>
    <item>
      <title>Wikimedia thumbnails now: thumb.wikimedia.org, a fixed list of widths, and WebP only for some clients</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Sat, 14 Nov 2026 05:49:34 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/wikimedia-thumbnails-now-thumbwikimediaorg-a-fixed-list-of-widths-and-webp-only-for-some-45am</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/wikimedia-thumbnails-now-thumbwikimediaorg-a-fixed-list-of-widths-and-webp-only-for-some-45am</guid>
      <description>&lt;p&gt;I keep a small rule in an image downloader extension that turns Wikipedia thumbnails into the original Commons files. This week the thumbnails on English Wikipedia started coming from a different host, so I went back with curl and measured what changed. Everything below was checked on 14 November 2026 against one file, the Einstein portrait in the English article (&lt;code&gt;Albert_Einstein_Head_cleaned.jpg&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  The new thumbnail address
&lt;/h2&gt;

&lt;p&gt;The article HTML now points at &lt;code&gt;thumb.wikimedia.org&lt;/code&gt;, with tracking parameters on the end:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//thumb.wikimedia.org/wikipedia/commons/thumb/2/28/Albert_Einstein_Head_cleaned.jpg/250px-Albert_Einstein_Head_cleaned.jpg?utm_source=en.wikipedia.org&amp;amp;utm_campaign=parser&amp;amp;utm_content=thumbnail
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The path after the host is the same one &lt;code&gt;upload.wikimedia.org&lt;/code&gt; has always used: &lt;code&gt;thumb/&lt;/code&gt;, the two hash directories, the file name, then &lt;code&gt;&amp;lt;width&amp;gt;px-&amp;lt;file name&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The old trick for the original still works, as long as you also change the host. Drop &lt;code&gt;thumb/&lt;/code&gt;, drop the last segment and the query, and request it from &lt;code&gt;upload.wikimedia.org&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://upload.wikimedia.org/wikipedia/commons/2/28/Albert_Einstein_Head_cleaned.jpg
→ 200, image/jpeg, 8,907,528 bytes (4,530 × 5,607)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same original path on the thumb host does not serve the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://thumb.wikimedia.org/wikipedia/commons/2/28/Albert_Einstein_Head_cleaned.jpg
→ 301 to https://commons.wikimedia.org/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So a rule that only strips &lt;code&gt;thumb/&lt;/code&gt; and the width segment, and keeps whatever host it found, now sends you to the Commons home page with a 301. Mine already rewrote the host, which is the only reason it kept working.&lt;/p&gt;

&lt;h2&gt;
  
  
  Only some widths exist
&lt;/h2&gt;

&lt;p&gt;Changing &lt;code&gt;250px&lt;/code&gt; to any number used to give you a thumbnail at that width. Now it doesn't. I requested the same file at 14 widths on &lt;code&gt;thumb.wikimedia.org&lt;/code&gt;, one second apart:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Width&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;120, 250, 330, 500, 960, 1280, 1920, 3840&lt;/td&gt;
&lt;td&gt;200&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;180, 320, 640, 800, 1024, 2560&lt;/td&gt;
&lt;td&gt;400&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The 400 is an HTML error page whose message reads "Use thumbnail sizes listed on &lt;a href="https://w.wiki/GHai" rel="noopener noreferrer"&gt;https://w.wiki/GHai&lt;/a&gt;". That short link goes to Wikimedia's list of standard thumbnail sizes. An extra pass earlier the same day on 20, 40 and 60 returned images, and 777 and 1200 returned 400.&lt;/p&gt;

&lt;p&gt;If you need an arbitrary width, &lt;code&gt;Special:FilePath&lt;/code&gt; still accepts one and rounds it up:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://commons.wikimedia.org/wiki/Special:FilePath/Albert_Einstein_Head_cleaned.jpg?width=777
→ 302 → Special:Redirect/file/...&amp;amp;width=777
→ final URL .../thumb/.../960px-Albert_Einstein_Head_cleaned.jpg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without &lt;code&gt;?width&lt;/code&gt; it ends at the original on &lt;code&gt;upload.wikimedia.org&lt;/code&gt;, 8,907,528 bytes again. Both final URLs pick up &lt;code&gt;utm_&lt;/code&gt; parameters on the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  WebP, but only if you ask exactly like Chrome
&lt;/h2&gt;

&lt;p&gt;Same 500px thumbnail, four &lt;code&gt;Accept&lt;/code&gt; headers:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Accept header&lt;/th&gt;
&lt;th&gt;Content-Type&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;none (curl default)&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;81,486&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/jpeg&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;81,486&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/avif,*/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/jpeg&lt;/td&gt;
&lt;td&gt;81,486&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;image/webp,*/*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;image/webp&lt;/td&gt;
&lt;td&gt;73,684&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Chrome's real image header (&lt;code&gt;image/avif,image/webp,image/apng,image/*,*/*;q=0.8&lt;/code&gt;) also got WebP. Both files decode to 500 × 619. AVIF in the header without WebP gets JPEG, so the switch looks for WebP specifically.&lt;/p&gt;

&lt;p&gt;The WebP response I got had no &lt;code&gt;Vary&lt;/code&gt; header, and it was a cache hit (&lt;code&gt;x-cache-status: hit-front&lt;/code&gt;, &lt;code&gt;age&lt;/code&gt; around 12 hours). I can't see how the caches keep the two variants apart from the outside. What matters for a downloader is the practical result: a browser extension that fetches a thumbnail with the browser's own headers gets a &lt;code&gt;.webp&lt;/code&gt; file even though the URL ends in &lt;code&gt;.jpg&lt;/code&gt;. If you save it under the URL's name, you get a WebP with a &lt;code&gt;.jpg&lt;/code&gt; extension. Sniff the bytes or read &lt;code&gt;Content-Type&lt;/code&gt; before you name the file.&lt;/p&gt;

&lt;p&gt;The original on &lt;code&gt;upload.wikimedia.org&lt;/code&gt; came back as JPEG for me in both cases. Only the thumbnails changed format.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rate limits
&lt;/h2&gt;

&lt;p&gt;My first loop over the widths had no delay and went to &lt;code&gt;upload.wikimedia.org&lt;/code&gt;. By the fifth request the widths on the list were answered with 429, while the widths off the list still got their 400, so that check runs before the limit. With a one-second gap on &lt;code&gt;thumb.wikimedia.org&lt;/code&gt; I got no 429s. If you script this, slow down and back off on 429; Wikimedia's user-agent policy also asks for a descriptive &lt;code&gt;User-Agent&lt;/code&gt; with contact details.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed
&lt;/h2&gt;

&lt;p&gt;Nothing in the extension: it already moved the host to &lt;code&gt;upload.wikimedia.org&lt;/code&gt; and fetched the original. I did rewrite the "edit the URL" steps in the &lt;a href="https://pixlasso.com/guides/download-images-from-wikipedia?src=devto" rel="noopener noreferrer"&gt;Wikipedia image download guide&lt;/a&gt;, since the method that told people to type any width now gives a 400 for most numbers they would try.&lt;/p&gt;

&lt;p&gt;One file is a small sample. The 400 page points at a published list rather than a per-file rule, so I expect the widths to hold elsewhere. The WebP switch and the missing &lt;code&gt;Vary&lt;/code&gt; header are worth re-checking on your own files before you rely on them.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>http</category>
      <category>images</category>
      <category>wikipedia</category>
    </item>
    <item>
      <title>Converting a brand palette from hex to OKLCH, and what the numbers do and don't tell you</title>
      <dc:creator>Casper Tran</dc:creator>
      <pubDate>Sat, 14 Nov 2026 04:45:49 +0000</pubDate>
      <link>https://dev.to/casper_tran_59c6a8b1e1f3d/converting-a-brand-palette-from-hex-to-oklch-and-what-the-numbers-do-and-dont-tell-you-348o</link>
      <guid>https://dev.to/casper_tran_59c6a8b1e1f3d/converting-a-brand-palette-from-hex-to-oklch-and-what-the-numbers-do-and-dont-tell-you-348o</guid>
      <description>&lt;p&gt;Tailwind v4's default colors and shadcn/ui's theme variables are written in &lt;code&gt;oklch()&lt;/code&gt;. If your brand palette lives in hex, at some point you convert it. Online converters work, but I wanted to see the math and check the numbers against a palette I know well, so here's a small converter and what the output taught me.&lt;/p&gt;

&lt;p&gt;The palette is from Northwind Roasters, a fictional coffee shop site I use for demos: cream background, terracotta primary, sage green accent, dark brown text.&lt;/p&gt;

&lt;h2&gt;
  
  
  The converter
&lt;/h2&gt;

&lt;p&gt;OKLCH is OKLab in polar form, and OKLab comes from Björn Ottosson's published matrices. From hex: undo the sRGB gamma, go to an LMS-like space, take cube roots, go to Lab, then turn a/b into chroma and hue.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;lin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="mf"&gt;0.04045&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;12.92&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.055&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mf"&gt;1.055&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="mf"&gt;2.4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;hexToOklch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;lin&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;parseInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;255&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.4122214708&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.5363325363&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.0514459929&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.2119034982&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.6806995451&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.1073969566&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;cbrt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0883024619&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.2817188376&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;g&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.6299787005&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;L&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.2104542553&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.793617785&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;0.0040720468&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;1.9779984951&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;2.428592205&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.4505937099&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;B&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;0.0259040371&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;l&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mf"&gt;0.7827717662&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mf"&gt;0.808675766&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;hypot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;B&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;H&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;C&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mf"&gt;0.0005&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;atan2&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;B&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;A&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;180&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;PI&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;360&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`oklch(${(L * 100).toFixed(1)}% ${C.toFixed(3)} ${H.toFixed(1)})`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;C &amp;lt; 0.0005&lt;/code&gt; check is for greys and white: with no chroma the hue is meaningless, and &lt;code&gt;atan2&lt;/code&gt; would return noise.&lt;/p&gt;

&lt;p&gt;Output for the palette:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Role&lt;/th&gt;
&lt;th&gt;Hex&lt;/th&gt;
&lt;th&gt;OKLCH&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;background&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#fffaf3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(98.7% 0.011 76.6)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;surface&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#f6eadb&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(94.2% 0.024 73.6)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;border&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#ead8c3&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(89.1% 0.035 71.6)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;muted text&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#7a6656&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(52.5% 0.035 60.6)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;primary&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#c2410c&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(55.3% 0.174 38.4)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;accent&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#4d7c5a&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(54.3% 0.074 152.1)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;text&lt;/td&gt;
&lt;td&gt;&lt;code&gt;#2b1d14&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;oklch(24.5% 0.027 53.8)&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;oklch(55.3% ...)&lt;/code&gt; and &lt;code&gt;oklch(0.553 ...)&lt;/code&gt; are the same color; CSS accepts lightness either way.&lt;/p&gt;

&lt;p&gt;You can read the palette from this table in a way you can't from hex: all the neutrals sit around hue 54 to 77 (warm), their chroma stays under 0.04 (barely tinted), and they step down in lightness from 98.7 to 24.5. The primary has five times the chroma of any neutral and more than twice that of the green accent.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Lightness is not contrast
&lt;/h2&gt;

&lt;p&gt;Primary and accent are almost the same OKLCH lightness, 55.3% and 54.3%. So I expected the accent, being slightly darker, to have slightly more contrast on the cream background. It's the other way round:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Color&lt;/th&gt;
&lt;th&gt;OKLCH L&lt;/th&gt;
&lt;th&gt;WCAG contrast on &lt;code&gt;#fffaf3&lt;/code&gt;
&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;primary &lt;code&gt;#c2410c&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;55.3%&lt;/td&gt;
&lt;td&gt;4.99:1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;accent &lt;code&gt;#4d7c5a&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;54.3%&lt;/td&gt;
&lt;td&gt;4.65:1&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;muted &lt;code&gt;#7a6656&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;52.5%&lt;/td&gt;
&lt;td&gt;5.24:1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;WCAG 2 contrast is built on relative luminance, a weighted sum of the linear sRGB channels in which green counts for about 72%. OKLCH lightness is designed to match how light a color looks, which is a different model. They usually agree in direction, but between two colors a point apart they can disagree, as here. OKLCH is great for building scales; still run the actual contrast check on the pairs you ship.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Lowering L alone falls out of gamut
&lt;/h2&gt;

&lt;p&gt;The obvious way to make a hover shade in OKLCH is to keep chroma and hue and lower the lightness. Converting back to sRGB shows what happens with a saturated color:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;oklch(55.3% 0.174 38.4)  -&amp;gt; #c2410b, in sRGB
oklch(50%   0.174 38.4)  -&amp;gt; blue channel -0.076, outside sRGB
oklch(47%   0.174 38.4)  -&amp;gt; blue channel -0.119, outside sRGB
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A negative channel means there's no sRGB color with that lightness, chroma and hue. CSS lets you write it anyway, and the browser has to map it to something the screen can show, so you don't get exactly what you wrote, and a wide-gamut screen may show something different from an sRGB one.&lt;/p&gt;

&lt;p&gt;The site's real hover color is &lt;code&gt;#9a3412&lt;/code&gt;, which is &lt;code&gt;oklch(47.0% 0.143 37.3)&lt;/code&gt;: the designer dropped the chroma from 0.174 to 0.143 while darkening. That's the pattern for saturated colors: lower L and C together. A quick way to check is to convert back and look for channels below 0 or above 1.&lt;/p&gt;

&lt;p&gt;It goes the other direction too. At the same lightness and hue, the primary's chroma can only go up to about 0.179 before the blue channel goes negative, so 0.174 is already close to the most saturated terracotta sRGB has at that lightness.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Rounding costs one step, and that's fine
&lt;/h2&gt;

&lt;p&gt;With three decimals, converting the primary back gives &lt;code&gt;#c2410b&lt;/code&gt;, not &lt;code&gt;#c2410c&lt;/code&gt;: the blue channel is off by one out of 255. That's invisible, but it means a round trip through the rounded oklch() string won't give you byte-identical hex. If a test compares the colors exactly, compare before rounding or allow a difference of one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using it for shadcn/ui
&lt;/h2&gt;

&lt;p&gt;With the values converted, the shadcn/ui mapping is: background to &lt;code&gt;--background&lt;/code&gt; and &lt;code&gt;--popover&lt;/code&gt;, surface to &lt;code&gt;--card&lt;/code&gt;, &lt;code&gt;--secondary&lt;/code&gt; and &lt;code&gt;--muted&lt;/code&gt;, text to &lt;code&gt;--foreground&lt;/code&gt; and the &lt;code&gt;-foreground&lt;/code&gt; variables, primary to &lt;code&gt;--primary&lt;/code&gt; and &lt;code&gt;--ring&lt;/code&gt;, border to &lt;code&gt;--border&lt;/code&gt; and &lt;code&gt;--input&lt;/code&gt;. White on the primary is 5.18:1, so &lt;code&gt;--primary-foreground&lt;/code&gt; can stay white.&lt;/p&gt;

&lt;p&gt;One thing to avoid: shadcn's &lt;code&gt;--accent&lt;/code&gt; is the background of a hovered menu item, not a brand color. Put the sage green there and every hover turns green. I keep it as a separate &lt;code&gt;--brand-accent&lt;/code&gt; and set &lt;code&gt;--accent&lt;/code&gt; to a faint tint of the text color.&lt;/p&gt;

&lt;h2&gt;
  
  
  Short version
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;The conversion is 15 lines of math; check it against a known value before trusting it.&lt;/li&gt;
&lt;li&gt;Read the OKLCH table for structure: hue family, how tinted the neutrals are, the lightness steps.&lt;/li&gt;
&lt;li&gt;Don't use OKLCH lightness as a contrast check. Compute WCAG contrast.&lt;/li&gt;
&lt;li&gt;Darken saturated colors by lowering L and C together, then convert back to make sure you're still in sRGB.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I made a Chrome extension, Stylasso, that reads a site's palette with roles and writes this kind of shadcn/ui theme in oklch(); its values for this demo site match the converter above to the last digit. There's a guide here: &lt;a href="https://stylasso.pixlasso.com/website-to-shadcn-theme?src=devto" rel="noopener noreferrer"&gt;turn any website into a shadcn/ui theme&lt;/a&gt;. If you already have your hex values, the converter is all you need.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Written with help from an AI assistant. Every value above comes from running the code shown on the demo palette.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>design</category>
      <category>webdev</category>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
