<?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: Oliver K.</title>
    <description>The latest articles on DEV Community by Oliver K. (@oliver_k_c5e4f0bad933014).</description>
    <link>https://dev.to/oliver_k_c5e4f0bad933014</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%2F4259029%2Fc3bdae41-5e64-4f49-b266-36f7146c59bb.png</url>
      <title>DEV Community: Oliver K.</title>
      <link>https://dev.to/oliver_k_c5e4f0bad933014</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/oliver_k_c5e4f0bad933014"/>
    <language>en</language>
    <item>
      <title>One "import * as Icons" line was shipping 5,727 icons to every visitor of our Next.js site</title>
      <dc:creator>Oliver K.</dc:creator>
      <pubDate>Sun, 22 Nov 2026 16:46:53 +0000</pubDate>
      <link>https://dev.to/oliver_k_c5e4f0bad933014/one-import-as-icons-line-was-shipping-5727-icons-to-every-visitor-of-our-nextjs-site-2km9</link>
      <guid>https://dev.to/oliver_k_c5e4f0bad933014/one-import-as-icons-line-was-shipping-5727-icons-to-every-visitor-of-our-nextjs-site-2km9</guid>
      <description>&lt;p&gt;I look after the marketing site for &lt;a href="https://fashiolabs.com/" rel="noopener noreferrer"&gt;Fashio&lt;/a&gt;, a small product that generates on-model photos and virtual try-ons for fashion e-commerce. The site is a Next.js 16 App Router project: mostly Server Components, markdown content with YAML frontmatter, 24 locales, and a handful of &lt;code&gt;"use client"&lt;/code&gt; components for menus and interactive bits.&lt;/p&gt;

&lt;p&gt;In August I was doing an accessibility pass and noticed the homepage was shipping roughly &lt;strong&gt;2 MB of JavaScript&lt;/strong&gt;. For a page that is mostly text, images and a mega-menu, that is absurd. This post is about where that weight came from, how I found it, and the two fixes that took the homepage from &lt;strong&gt;1995 KB to 676 KB&lt;/strong&gt; of JS.&lt;/p&gt;

&lt;p&gt;Neither cause showed up in Lighthouse. That is the part I would like you to take away.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers first
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Before&lt;/th&gt;
&lt;th&gt;After icon fix&lt;/th&gt;
&lt;th&gt;After both fixes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Homepage JS&lt;/td&gt;
&lt;td&gt;1995 KB&lt;/td&gt;
&lt;td&gt;1399 KB&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;676 KB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Average page JS&lt;/td&gt;
&lt;td&gt;1443 KB&lt;/td&gt;
&lt;td&gt;–&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;675 KB&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That is a 66% cut on the homepage, and the average page landed in the same place because both problems lived in components that wrap every route.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lighthouse was looking somewhere else
&lt;/h2&gt;

&lt;p&gt;The Lighthouse report I started from had a "reduce unused JavaScript" section, but the largest single saving it listed was a &lt;strong&gt;13.7 KiB polyfill&lt;/strong&gt;. Nothing in it said "you are shipping an entire icon library" or "you are shipping 23 languages nobody asked for".&lt;/p&gt;

&lt;p&gt;That makes sense in hindsight. Lighthouse sees chunks, not the import statements that produced them. When one big chunk is made of hundreds of tiny modules that each "might be used", the report has nothing obvious to point at.&lt;/p&gt;

&lt;p&gt;So instead of reading the report harder, I went to the build output and grepped the emitted chunks under &lt;code&gt;.next/static/chunks/&lt;/code&gt; for library fingerprints: strings you know belong to one specific package. An icon library is easy to spot because every icon carries its own name and SVG path data. Once a chunk is full of icon names you have never used anywhere on the site, you know what you are looking at.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cause 1: the namespace import
&lt;/h2&gt;

&lt;p&gt;Three components rendered icons by name: &lt;code&gt;FeaturesGrid&lt;/code&gt;, &lt;code&gt;FeatureCard&lt;/code&gt; and the site &lt;code&gt;Layout&lt;/code&gt;. The names come from data, not code. The &lt;code&gt;FEATURES&lt;/code&gt; array in &lt;code&gt;constants.ts&lt;/code&gt; has an &lt;code&gt;iconName&lt;/code&gt; per product, and our service pages carry icons in their markdown frontmatter. For example, the page for our &lt;a href="https://fashiolabs.com/ghost-mannequin-generator" rel="noopener noreferrer"&gt;ghost mannequin generator&lt;/a&gt; lists its feature cards like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# content/services/ghost-mannequin-generator.md (trimmed)
&lt;/span&gt;  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Auto Neck Joint"&lt;/span&gt;
    &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Link"&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Mannequin Removal"&lt;/span&gt;
    &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Eraser"&lt;/span&gt;
  &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Symmetry Correction"&lt;/span&gt;
    &lt;span class="na"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"AlignCenter"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The component side looked like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// components/FeaturesGrid.tsx (before, trimmed)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;Icons&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"lucide-react"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;features&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;feature&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&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="nc"&gt;IconComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Icons&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kt"&gt;any&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;feature&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;icon&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nc"&gt;Icons&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Box&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="cm"&gt;/* ...&amp;lt;IconComponent /&amp;gt; inside the card */&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It reads nicely and it works. It also defeats tree-shaking completely. Once you write &lt;code&gt;Icons[someString]&lt;/code&gt;, the bundler cannot know which exports you will reach for at runtime, so it keeps all of them. &lt;code&gt;lucide-react&lt;/code&gt; 0.562.0 exports &lt;strong&gt;5,727&lt;/strong&gt; symbols:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ node -e &lt;span class="s1"&gt;'console.log(Object.keys(require("lucide-react")).length)'&lt;/span&gt;
5727
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We use &lt;strong&gt;90&lt;/strong&gt;. And because &lt;code&gt;Layout&lt;/code&gt; is a client component that wraps every page, every visitor on every route downloaded all 5,727.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: an explicit registry
&lt;/h3&gt;

&lt;p&gt;Tree-shaking needs static, named imports, so the fix is boring on purpose. One file imports exactly the icons we use and exposes a lookup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// utils/icons.ts (trimmed)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;AlertCircle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;ArrowRight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Camera&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Layers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Sparkles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ...90 in total&lt;/span&gt;
  &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nc"&gt;LucideIcon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"lucide-react"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;ICONS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;LucideIcon&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;AlertCircle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;ArrowRight&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Box&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Camera&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Layers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;Sparkles&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/** Never returns undefined; unknown names fall back to Box. */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getIcon&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="o"&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="nc"&gt;LucideIcon&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;name&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="no"&gt;ICONS&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&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="nc"&gt;Box&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;Each call site became a one-line change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;// components/FeatureCard.tsx
&lt;span class="gd"&gt;-import * as Icons from "lucide-react";&lt;/span&gt;
&lt;span class="gi"&gt;+import { getIcon } from "@/utils/icons";&lt;/span&gt;

&lt;span class="gd"&gt;-  const IconComponent = (Icons as any)[feature.iconName] || Icons.Star;&lt;/span&gt;
&lt;span class="gi"&gt;+  const IconComponent = getIcon(feature.iconName);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That alone took the homepage from 1995 KB to 1399 KB, about 596 KB or 30% of the JS.&lt;/p&gt;

&lt;p&gt;The trade-off is real and I wrote it into the file header: icon names still arrive as strings from &lt;code&gt;constants.ts&lt;/code&gt; and from frontmatter, so &lt;strong&gt;adding a new icon name in content means adding it to &lt;code&gt;utils/icons.ts&lt;/code&gt; too&lt;/strong&gt;, or it silently renders a &lt;code&gt;Box&lt;/code&gt;. I accepted that. A content editor seeing a box instead of a shirt is a much smaller problem than every visitor downloading thousands of icons they never see.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cause 2: every locale in the client layout
&lt;/h2&gt;

&lt;p&gt;1399 KB was still far too much, so I went back to the chunks. The next fingerprint was easier to recognise because it was human-readable: translated message strings from all 24 locales, sitting in the bundle for the English homepage.&lt;/p&gt;

&lt;p&gt;The site has 24 locales. &lt;code&gt;components/Layout.tsx&lt;/code&gt; is &lt;code&gt;"use client"&lt;/code&gt; (it handles the mobile menu and the mega-menu) and it needed the translated nav and footer labels. It got them like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// components/Layout.tsx (before, trimmed)&lt;/span&gt;
&lt;span class="s2"&gt;"use client"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;getSiteMessages&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"@/i18n/messages"&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;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;makeT&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;getSiteMessages&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@/i18n/messages&lt;/code&gt; is a barrel. It statically imports &lt;strong&gt;every namespace of every locale&lt;/strong&gt; (pricing copy, landing page copy, legal text) so that server pages can ask for whatever they need. On the server that is fine. Pulled into a client component, it put about &lt;strong&gt;1.3 MB of message tables&lt;/strong&gt; into the browser bundle so &lt;code&gt;Layout&lt;/code&gt; could read a few kilobytes of nav labels.&lt;/p&gt;

&lt;h3&gt;
  
  
  The fix: a module that imports only the chrome
&lt;/h3&gt;

&lt;p&gt;I added a new module next to the barrel instead of changing it. A parallel i18n refactor was editing &lt;code&gt;i18n/messages/index.ts&lt;/code&gt; at the same time, and I did not want a merge fight over a file I did not own.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// i18n/siteChrome.ts (trimmed)&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="no"&gt;DEFAULT_LOCALE&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./locales"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;site&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;enSite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./messages/en/site"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;site&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;deSite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./messages/de/site"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;site&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;frSite&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s2"&gt;"./messages/fr/site"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// ...one `site.ts` import per locale, nothing else&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;SITE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Record&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Messages&lt;/span&gt;&lt;span class="o"&gt;&amp;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;de&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;deSite&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;frSite&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/** Falls back to English for any key a locale has not translated. */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getSiteChrome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Messages&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;loc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;SITE&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;locale&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;loc&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="no"&gt;DEFAULT_LOCALE&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;enSite&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;loc&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;enSite&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;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;// components/Layout.tsx
&lt;span class="gd"&gt;-import { getSiteMessages } from "@/i18n/messages";&lt;/span&gt;
&lt;span class="gi"&gt;+import { getSiteChrome } from "@/i18n/siteChrome";&lt;/span&gt;

&lt;span class="gd"&gt;-  const t = makeT(getSiteMessages(locale) as Record&amp;lt;string, string&amp;gt;);&lt;/span&gt;
&lt;span class="gi"&gt;+  const t = makeT(getSiteChrome(locale) as Record&amp;lt;string, string&amp;gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;site.ts&lt;/code&gt; files across all 24 locales come to about 96 KB of source, against 1.3 MB for the full barrel. The bundle dropped by roughly 723 KB, and the homepage landed at &lt;strong&gt;676 KB&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why I did not lazy-load the locales
&lt;/h3&gt;

&lt;p&gt;The obvious next step is a dynamic &lt;code&gt;import(`./messages/${locale}/site`)&lt;/code&gt; so each visitor gets one language. I decided against it, and that was on purpose.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Layout&lt;/code&gt; reads the locale from &lt;code&gt;usePathname()&lt;/code&gt;, which also runs during SSR. With a synchronous lookup the server renders French nav on &lt;code&gt;/fr/*&lt;/code&gt;, in the HTML, before any JavaScript runs. With a dynamic import the first render would fall back to English, and the French labels would swap in after hydration. Users would see a flash, and crawlers would get English navigation on French URLs. For a site with 24 locales that rely on organic search, that is a bad trade for saving a few dozen kilobytes more.&lt;/p&gt;

&lt;p&gt;I checked the built HTML afterwards. &lt;code&gt;/fr&lt;/code&gt; renders "Tarifs · Shooting IA", &lt;code&gt;/de&lt;/code&gt; renders "Preise · KI-Fotoshooting", and &lt;code&gt;/ja&lt;/code&gt; renders in Japanese, all server-side.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I got wrong
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;I trusted the audit to find the problem.&lt;/strong&gt; I started from the Lighthouse report, whose biggest item was worth 13.7 KiB. The two problems worth more than 1.3 MB between them were in no report. Grepping the build output took a few minutes, and I should have started there.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I wrote the bug in the first place, in three files.&lt;/strong&gt; &lt;code&gt;(Icons as any)[name]&lt;/code&gt; came from wanting icons to be configurable from markdown. The &lt;code&gt;as any&lt;/code&gt; should have been the warning: once a lookup needs a cast to compile, the bundler probably cannot see through it either.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My refactor quietly changed a fallback.&lt;/strong&gt; &lt;code&gt;FeatureCard&lt;/code&gt; used to fall back to &lt;code&gt;Icons.Star&lt;/code&gt;; the other two components fell back to &lt;code&gt;Box&lt;/code&gt;. &lt;code&gt;getIcon()&lt;/code&gt; uses &lt;code&gt;Box&lt;/code&gt; everywhere, and its doc comment says "as before", which is only true for two of the three call sites. Nobody has noticed, because every &lt;code&gt;iconName&lt;/code&gt; in &lt;code&gt;constants.ts&lt;/code&gt; is in the registry today, so nothing falls back on a feature card. It is still a behaviour change I did not mean to make, and it is exactly what "one-line change at each call site" diffs hide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The registry fails silently by design.&lt;/strong&gt; At least one icon name in our markdown, &lt;code&gt;HighDefinition&lt;/code&gt;, does not exist in lucide at all. It fell back to a box before and it still does. A build-time check that compares every &lt;code&gt;icon:&lt;/code&gt; and &lt;code&gt;iconName&lt;/code&gt; value against the keys of &lt;code&gt;ICONS&lt;/code&gt; would catch both a typo and a forgotten registry entry. I have not written it yet.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A separate i18n change broke the build that same day.&lt;/strong&gt; Two new English message files were annotated &lt;code&gt;export const about: Messages = {}&lt;/code&gt;, but &lt;code&gt;Messages&lt;/code&gt; is &lt;em&gt;derived from&lt;/em&gt; the English tables, so TypeScript reported &lt;code&gt;'about' is referenced directly or indirectly in its own type annotation&lt;/code&gt;. The fix was to remove the annotation. Every other English file already left it off, and only the other locales annotate against the derived type. It had nothing to do with bundle size, but it cost me time while I was trying to measure a build that would not finish.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checklist if your Next.js bundle looks too big
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Look at the emitted chunks, not just the Lighthouse summary. Search them for strings from libraries you suspect.&lt;/li&gt;
&lt;li&gt;Search the codebase for &lt;code&gt;import * as&lt;/code&gt; from any large package, especially icon sets, date libraries and lodash-style utility packages.&lt;/li&gt;
&lt;li&gt;Check every &lt;code&gt;"use client"&lt;/code&gt; component that wraps many routes (layouts, headers, providers). Whatever it imports ships everywhere.&lt;/li&gt;
&lt;li&gt;Be careful with barrels (&lt;code&gt;index.ts&lt;/code&gt; that re-exports a lot) imported from client code. A server-side convenience becomes a client-side payload.&lt;/li&gt;
&lt;li&gt;Before lazy-loading anything that affects rendered text, check what SSR outputs without it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are curious what the site actually does, it turns flat-lay product photos into &lt;a href="https://fashiolabs.com/" rel="noopener noreferrer"&gt;AI fashion models for e-commerce&lt;/a&gt; catalogs, and the mega-menu that used to carry all those icons now links to pages like &lt;a href="https://fashiolabs.com/virtual-ai-fashion-try-on" rel="noopener noreferrer"&gt;virtual try-on&lt;/a&gt; at a third of the weight.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This post was written with AI assistance and reviewed by the author.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>nextjs</category>
      <category>performance</category>
    </item>
    <item>
      <title>59 of 102 faces came out "round": calibrating an in-browser MediaPipe classifier against a research face set</title>
      <dc:creator>Oliver K.</dc:creator>
      <pubDate>Sun, 22 Nov 2026 16:46:00 +0000</pubDate>
      <link>https://dev.to/oliver_k_c5e4f0bad933014/59-of-102-faces-came-out-round-calibrating-an-in-browser-mediapipe-classifier-against-a-research-59ni</link>
      <guid>https://dev.to/oliver_k_c5e4f0bad933014/59-of-102-faces-came-out-round-calibrating-an-in-browser-mediapipe-classifier-against-a-research-59ni</guid>
      <description>&lt;p&gt;Most face-shape tools on the web have the same problem: whatever photo you give them, they hand back a confident label. Ours did too. For a while our classifier called 9 out of 9 real test photos "Diamond". After I fixed that, it looked fine on every sample photo I tried, and it was still wrong for most real users.&lt;/p&gt;

&lt;p&gt;I work on &lt;a href="https://thefaceanalysis.com/" rel="noopener noreferrer"&gt;The Face Analysis&lt;/a&gt;, a free in-browser face analysis site. This post is about how we found out: running the site's own measurement code on a public research face set and changing the engine based on the numbers, not on how the output looked.&lt;/p&gt;

&lt;p&gt;Everything below runs client-side: MediaPipe Face Landmarker (&lt;code&gt;@mediapipe/tasks-vision&lt;/code&gt; 1.0.1, WASM) places 478 points on one photo, and plain TypeScript turns those points into ratios.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline in one paragraph
&lt;/h2&gt;

&lt;p&gt;The landmarker returns 468 face points plus 10 iris points, each with normalized &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt; and a relative &lt;code&gt;z&lt;/code&gt;. Every measurement is 2D geometry over a handful of those indices; &lt;code&gt;z&lt;/code&gt; is ignored on purpose because its scale differs from x/y. The WASM bundle and model download only when the user starts an analysis (about 3 MB, which would wreck LCP if it loaded with the page), and the photo stays in the browser the whole time.&lt;/p&gt;

&lt;p&gt;The indices that matter for face shape (from &lt;code&gt;lib/analysis/geometry.ts&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;Measurement&lt;/th&gt;
&lt;th&gt;Landmarks&lt;/th&gt;
&lt;th&gt;Note&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Face length&lt;/td&gt;
&lt;td&gt;10 → 152&lt;/td&gt;
&lt;td&gt;10 is the top of the forehead surface, &lt;strong&gt;not&lt;/strong&gt; the hairline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cheekbone width&lt;/td&gt;
&lt;td&gt;234 ↔ 454&lt;/td&gt;
&lt;td&gt;the widest point on every face we measured&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forehead width&lt;/td&gt;
&lt;td&gt;21 ↔ 251&lt;/td&gt;
&lt;td&gt;temples; 70/300 (brow tips) were the original choice and were wrong&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jaw width&lt;/td&gt;
&lt;td&gt;172 ↔ 397&lt;/td&gt;
&lt;td&gt;gonial area&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pupils (iris centres)&lt;/td&gt;
&lt;td&gt;468, 473&lt;/td&gt;
&lt;td&gt;only present in the 478-point mesh&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h2&gt;
  
  
  Bug #1: the forehead was measured at the eyebrows
&lt;/h2&gt;

&lt;p&gt;The first version measured forehead width between 70 and 300, the outer ends of the eyebrows. On 27 faces that distance came out at 0.84–0.89 of cheekbone width. Diamond's first condition is "cheekbones clearly wider than forehead", so it was true for practically every face. Switching to the temple points 21/251 gave 0.92–1.00 on the same faces.&lt;/p&gt;

&lt;p&gt;There was a second problem. The length thresholds (1.2 / 1.5 / 1.6) came from the usual face-shape taxonomy, but that taxonomy measures length from the &lt;strong&gt;hairline&lt;/strong&gt;, and landmark 10 sits well below it. Our length-to-width values on 32 faces ran from 1.119 to 1.347, so the "&amp;gt; 1.5 is oval", "&amp;lt; 1.2 is round/square" and "&amp;gt; 1.6 is oblong" rules mostly couldn't fire. Diamond was the only label left. The thresholds came from someone else's ruler.&lt;/p&gt;

&lt;p&gt;I recalibrated on those 32 faces and all seven labels became reachable. But most of the 32 were synthetic, and none were labelled. That turned out to matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring the engine on real faces
&lt;/h2&gt;

&lt;p&gt;For real data we used the &lt;strong&gt;Face Research Lab London Set&lt;/strong&gt; (DeBruine &amp;amp; Jones, figshare doi:10.6084/m9.figshare.5047666, CC BY 4.0). It has 102 adults (49 women, 53 men, ages 18–54), neutral and smiling front photos, attractiveness ratings from 2,513 raters, and researcher-placed 189-point templates. The photos are not in our repo and we don't republish them.&lt;/p&gt;

&lt;p&gt;The harness has two rules: use the &lt;strong&gt;same&lt;/strong&gt; model build the site ships, and run the &lt;strong&gt;same&lt;/strong&gt; &lt;code&gt;analyzeLandmarks&lt;/code&gt; function, compiled from the site's TypeScript. Extraction drives a real Chrome through Playwright, because the engine needs WASM and WebGL and doesn't run in plain Node:&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="c1"&gt;// extract-landmarks.mjs (study folder, trimmed)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;chromium&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;launch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"chrome"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headless&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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;p&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;newPage&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;await&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@1.0.1/vision_bundle.mjs"&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;fs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FilesetResolver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forVisionTasks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s2"&gt;"https://cdn.jsdelivr.net/npm/@mediapipe/tasks-vision@1.0.1/wasm"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;__lm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FaceLandmarker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createFromOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;baseOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;modelAssetPath&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;MODEL_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delegate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"GPU"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;runningMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"IMAGE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;numFaces&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="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="c1"&gt;// ...for each photo: decode, detect, keep { x, y, z } for all points&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;measure.mjs&lt;/code&gt; then feeds the stored landmarks into the compiled engine under several conditions: neutral, smiling, rolled 5° and 10°, downscaled to 338 px, darkened to 45%, a three-quarter view, and a &lt;strong&gt;3:4 portrait crop&lt;/strong&gt;. The model found a face in all 102 photos under every condition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug #2: the one that never threw
&lt;/h2&gt;

&lt;p&gt;The 3:4 crop condition is where the worst bug showed up. MediaPipe normalizes &lt;code&gt;x&lt;/code&gt; by image &lt;strong&gt;width&lt;/strong&gt; and &lt;code&gt;y&lt;/code&gt; by image &lt;strong&gt;height&lt;/strong&gt;. Our distance function treated them as the same unit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/analysis/geometry.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;dist&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="nc"&gt;Landmark&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="nc"&gt;Landmark&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&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;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;x&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;y&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="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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a square photo that's correct. On a 3:4 phone portrait, a horizontal distance in normalized units is 4/3 of the same distance measured vertically. Every face looks wider than it is. Length-to-width ratios drop, jaw angles and eye-tilt angles shift, and symmetry moves too.&lt;/p&gt;

&lt;p&gt;When we cropped the same 102 faces to 3:4, the old engine changed the face-shape label on 27 of them and called 59 of them "round".&lt;/p&gt;

&lt;p&gt;It never crashed or returned &lt;code&gt;NaN&lt;/code&gt;; every label was a valid label. Our sample photos were all square, so the dev loop looked correct, while phone selfies are almost never square.&lt;/p&gt;

&lt;p&gt;The fix is one function that rescales &lt;code&gt;x&lt;/code&gt; into height units before any measuring happens. Ratios are scale-invariant, so nothing else in the engine had to change:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/analysis/geometry.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;toUniformScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;l&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Landmarks&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="kt"&gt;number&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="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Landmarks&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;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;height&lt;/span&gt; &lt;span class="o"&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;height&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;l&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;k&lt;/span&gt; &lt;span class="o"&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;height&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;l&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="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="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;x&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="n"&gt;x&lt;/span&gt; &lt;span class="o"&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="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;It has to be applied at the boundary, and only to the measurement path. Drawing code (the mesh overlay on the photo) still needs the original normalized points:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/analysis/index.ts — analyzeImageDetailed()&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;landmarks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;detectLandmarks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;img&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="nf"&gt;hasAllPoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;landmarks&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NoFaceError&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;// Measure with uniform-scale points; draw and sample colour with the normalized ones.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;analyzeLandmarks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;toUniformScale&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;landmarks&lt;/span&gt;&lt;span class="p"&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;naturalWidth&lt;/span&gt;&lt;span class="p"&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;naturalHeight&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;After the fix, the 3:4 crop changes the label on 11 of 102 faces. That's in line with the landmark noise you get from simply rotating the photo, which I come back to below. The camera alignment path and the showcase got the same correction. The lesson I took away: &lt;strong&gt;test geometry code with non-square images.&lt;/strong&gt; A square sample image means this whole class of bug can't show up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bug #3: thresholds that didn't generalize
&lt;/h2&gt;

&lt;p&gt;With the aspect ratio fixed, the face-shape split on the 102 neutral faces was still badly off. We had calibrated on 32 mostly synthetic faces, and that didn't carry over to real ones:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Label&lt;/th&gt;
&lt;th&gt;Old thresholds&lt;/th&gt;
&lt;th&gt;Recalibrated&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Oval&lt;/td&gt;
&lt;td&gt;16&lt;/td&gt;
&lt;td&gt;38&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Round&lt;/td&gt;
&lt;td&gt;32&lt;/td&gt;
&lt;td&gt;13&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Triangle&lt;/td&gt;
&lt;td&gt;34 (30 of 53 men)&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Square&lt;/td&gt;
&lt;td&gt;15&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Diamond&lt;/td&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;9&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Heart&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Oblong&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Two labels never occurred at all. The distributions explain why:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Ratio (London set, n = 102)&lt;/th&gt;
&lt;th&gt;p10&lt;/th&gt;
&lt;th&gt;Median&lt;/th&gt;
&lt;th&gt;p90&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Length ÷ cheekbone width&lt;/td&gt;
&lt;td&gt;1.12&lt;/td&gt;
&lt;td&gt;1.18&lt;/td&gt;
&lt;td&gt;1.23&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Jaw ÷ cheekbone&lt;/td&gt;
&lt;td&gt;0.77&lt;/td&gt;
&lt;td&gt;0.79&lt;/td&gt;
&lt;td&gt;0.82&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forehead (temples) ÷ cheekbone&lt;/td&gt;
&lt;td&gt;0.91&lt;/td&gt;
&lt;td&gt;0.94&lt;/td&gt;
&lt;td&gt;0.97&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Forehead ÷ jaw&lt;/td&gt;
&lt;td&gt;1.12&lt;/td&gt;
&lt;td&gt;1.19&lt;/td&gt;
&lt;td&gt;1.25&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The old oblong cut-off was 1.32 and nobody's length ratio got there. The heart cut-off (forehead ÷ jaw ≥ 1.30) sat above the 90th percentile too.&lt;/p&gt;

&lt;p&gt;The new thresholds come from this set's percentiles, chosen by a search that balanced two goals: every label should be reachable at a plausible rate, and small photo changes (5° and 10° rotation, downscaling, darkening) should flip labels as rarely as possible. They live in one exported object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/analysis/faceShape.ts (trimmed)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;FACE_SHAPE_RULES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="n"&gt;oblongRatio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.229&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;triangleJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.794&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;triangleForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.125&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;roundRatio&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;roundJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.791&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;squareJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.796&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;squareForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.158&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;heartForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.239&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;diamondForehead&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.934&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;diamondJaw&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.796&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&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;ratio&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;oblongRatio&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"oblong"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// Must come BEFORE square, or square swallows it.&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;jaw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;triangleJaw&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;foreheadToJaw&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;triangleForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"triangle"&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;ratio&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;roundRatio&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;jaw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;roundJaw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"round"&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;jaw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;squareJaw&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;foreheadToJaw&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;squareForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"square"&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;foreheadToJaw&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;heartForeheadToJaw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"heart"&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;forehead&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;diamondForehead&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;jaw&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;diamondJaw&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"diamond"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;"oval"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two things here took me too long to learn. First, &lt;strong&gt;rule order is part of the model&lt;/strong&gt;. A rule placed after a broader rule never fires, and an earlier version had a dead branch for exactly that reason. A small verification script in our &lt;code&gt;make check&lt;/code&gt; now builds synthetic landmarks and asserts that every label in our eye classifier can be reached, because that kind of bug also fails silently. Second, the page copy that explains the rules on the &lt;a href="https://thefaceanalysis.com/face-shape-detector" rel="noopener noreferrer"&gt;face shape detector&lt;/a&gt; reads its numbers from &lt;code&gt;FACE_SHAPE_RULES&lt;/code&gt;, so the text and the engine can't drift apart again.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same pattern elsewhere: lips and iris scale
&lt;/h2&gt;

&lt;p&gt;The same dataset caught two more bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Downturned lips.&lt;/strong&gt; The threshold was 0°, which looks like the obvious "flat mouth" line. But on neutral faces the corner angle is negative because of how the landmarks sit: p10 −7.2°, median −3.0°, p90 +1.4°. With a 0° cut-off, 82 of 102 neutral faces were labelled downturned. The constant is now &lt;code&gt;DOWNTURNED_MAX_DEG = -6.5&lt;/code&gt;, roughly the bottom 15% of the neutral distribution, and 19 faces get the label.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pupillary distance.&lt;/strong&gt; This is the only absolute (mm) measurement on the site. It uses the iris as a ruler, assuming a horizontal visible iris diameter of about 11.7 mm. Comparing against the researchers' hand-marked iris borders showed that MediaPipe's iris diameter reads a median 5.9% too large, while the pupil-to-pupil distance matches the hand marks within 0.3%. So the error was in the scale, not in PD itself. After a &lt;code&gt;×1.059&lt;/code&gt; correction, the median PD moved from 58.4 mm to 61.9 mm, and the error band we state went from ±2 mm to ±3 mm, which is the honest figure.&lt;/p&gt;

&lt;h2&gt;
  
  
  fWHR: publishing the reference instead of a verdict
&lt;/h2&gt;

&lt;p&gt;On its own, an fWHR of 1.85 tells you nothing. Published means depend on the definition (brow or eyelid), the camera and the sample. So the &lt;a href="https://thefaceanalysis.com/fwhr-calculator" rel="noopener noreferrer"&gt;fWHR calculator&lt;/a&gt; places your number in a distribution measured with the same engine: bizygomatic width (234/454) divided by the height from the upper lip to the brow midpoint, both measured along axes aligned to the eye line so that head roll doesn't mix width into height.&lt;/p&gt;

&lt;p&gt;On the London set: &lt;strong&gt;median 1.78&lt;/strong&gt; (women 1.72, men 1.82), p10 1.64, p90 1.95. All 102 values ship as a sorted array in &lt;code&gt;lib/analysis/ratioReference.ts&lt;/code&gt;, and the percentile function deliberately refuses to claim precision that 102 faces can't support:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// lib/analysis/ratioReference.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;referencePercentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="kt"&gt;number&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="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;number&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;below&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;equal&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="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;x&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="n"&gt;ref&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;x&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&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;below&lt;/span&gt;&lt;span class="o"&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="n"&gt;x&lt;/span&gt; &lt;span class="o"&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;equal&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;99&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;max&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="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="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;below&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;equal&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="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;ref&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="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="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 same check produced a result we didn't like. The site's overall composite score &lt;strong&gt;did not predict&lt;/strong&gt; human attractiveness ratings on this set (Spearman ρ ≈ −0.07, confidence interval spanning zero). We didn't tune it until it did. The score is now presented as a percentile against the 102 faces, and the &lt;a href="https://thefaceanalysis.com/methodology" rel="noopener noreferrer"&gt;methodology page&lt;/a&gt; says plainly that it isn't an attractiveness rating.&lt;/p&gt;

&lt;h2&gt;
  
  
  What never leaves the browser
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The photo.&lt;/strong&gt; Detection and measurement run locally. The free tools make no upload request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The mesh.&lt;/strong&gt; &lt;code&gt;analyzeImageDetailed&lt;/code&gt; returns landmarks &lt;em&gt;beside&lt;/em&gt; the result object, not inside it. The overlay draws them and then drops them. A 478-point mesh is closer to a face template than a set of ratios, so it isn't persisted.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;History.&lt;/strong&gt; The last 50 results go to &lt;code&gt;localStorage&lt;/code&gt; under &lt;code&gt;tfa.measurements.v1&lt;/code&gt;, and they're only numbers: score, symmetry, shape labels, tilt, PD. No image and no landmarks.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://thefaceanalysis.com/embed" rel="noopener noreferrer"&gt;embeddable widgets&lt;/a&gt; run the same engine inside an iframe, with no analytics and no cookies in the frame.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No labelled ground truth.&lt;/strong&gt; Nobody in the London set has a "true" face shape. The thresholds spread real faces across the seven labels in a plausible way, and that's all we claim. We don't claim an accuracy rate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Borderline faces flip.&lt;/strong&gt; Across the four small perturbations (two rotations, downscale, darken), about 17% of faces change face-shape label after recalibration. The pages say so.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pose and expression matter a lot.&lt;/strong&gt; In the first robustness run, a smile changed the face-shape label on 36 of 102 faces and a three-quarter view changed 98 of them. Use a straight-on, neutral, evenly lit photo.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One dataset.&lt;/strong&gt; 102 adults photographed in London in 2012 isn't the world. The cohort is mostly white, and the engine doesn't know sex even where medians differ by sex.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not medical.&lt;/strong&gt; These are ratios from a photo. They aren't a diagnosis, and they aren't a recommendation to change anything about your face.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Takeaways for anyone shipping landmark geometry
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Normalize coordinates to one unit at the boundary; test with non-square images.&lt;/li&gt;
&lt;li&gt;Don't borrow thresholds from a taxonomy that measures different points.&lt;/li&gt;
&lt;li&gt;Calibrate on real faces with the exact model build you ship.&lt;/li&gt;
&lt;li&gt;Assert every label is reachable. Rule order is logic.&lt;/li&gt;
&lt;li&gt;When the data contradicts a feature, publish the contradiction.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you want to see the result, the free tools are on thefaceanalysis.com. I'm happy to answer questions about the harness or the geometry in the comments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article was written with AI assistance and reviewed and edited by the author.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>machinelearning</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
