<?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: Jo-Tung Wu</title>
    <description>The latest articles on DEV Community by Jo-Tung Wu (@jo_tungwu_19cab1323e4b66).</description>
    <link>https://dev.to/jo_tungwu_19cab1323e4b66</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%2F4252045%2F2716498e-0a6a-49f6-8ae0-86641d38416e.jpg</url>
      <title>DEV Community: Jo-Tung Wu</title>
      <link>https://dev.to/jo_tungwu_19cab1323e4b66</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jo_tungwu_19cab1323e4b66"/>
    <language>en</language>
    <item>
      <title>How we generated 300 template pages without making doorway pages</title>
      <dc:creator>Jo-Tung Wu</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:04:30 +0000</pubDate>
      <link>https://dev.to/jo_tungwu_19cab1323e4b66/how-we-generated-300-template-pages-without-making-doorway-pages-pn0</link>
      <guid>https://dev.to/jo_tungwu_19cab1323e4b66/how-we-generated-300-template-pages-without-making-doorway-pages-pn0</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on the &lt;a href="https://nexupira.com/news/programmatic-quote-templates" rel="noopener noreferrer"&gt;NEXUPIRA engineering blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our marketing site has a quote template for each of 100 trades, from air-conditioning installers to boxed-lunch caterers, in English, Traditional Chinese and Japanese. That is 300 pages, and each one offers the same quote as a free Excel file and a free Word file: 600 downloads. All of it is generated from one typed data set.&lt;/p&gt;

&lt;p&gt;"Generated pages for 100 keywords" is also a fair description of a doorway site. Google's spam policies name &lt;a href="https://developers.google.com/search/docs/essentials/spam-policies#doorways" rel="noopener noreferrer"&gt;doorway pages&lt;/a&gt; explicitly: pages made to rank for many similar queries that are substantially similar to each other and less useful than they look. So the rule we set before writing any code was that a page only exists if it says something about its trade, in its market, that no other page says. This post is about how we tried to hold that rule at scale and how we checked it. The numbers are measured, and the code is what runs on main today, trimmed.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape of it
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;One data set, three outputs:&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Output&lt;/th&gt;
&lt;th&gt;Count&lt;/th&gt;
&lt;th&gt;Built&lt;/th&gt;
&lt;th&gt;Notes&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Template pages&lt;/td&gt;
&lt;td&gt;300&lt;/td&gt;
&lt;td&gt;rendered on the server&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/templates/quote/&amp;lt;slug&amp;gt;&lt;/code&gt;, &lt;code&gt;/zh/…&lt;/code&gt;, &lt;code&gt;/ja/…&lt;/code&gt;; title and description patterns with length budgets; canonical, hreflang, sitemap&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Excel and Word files&lt;/td&gt;
&lt;td&gt;600&lt;/td&gt;
&lt;td&gt;generated at commit time&lt;/td&gt;
&lt;td&gt;live formulas with cached results; 10% / 8% tax by row in Japanese; byte-for-byte reproducible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Free quote tool presets&lt;/td&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;in the app&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;/tools/quote?preset=&amp;lt;slug&amp;gt;&lt;/code&gt;, same slugs, same line items&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Tests check that the stated count equals the data, every trade is linked from another trade, every file still matches its data, and English URLs stay under the prefixes our edge routes to the site.&lt;/p&gt;

&lt;p&gt;One set of TypeScript files feeds three things: the pages, the downloadable files, and the presets of the free quote tool in our app (&lt;code&gt;/tools/quote?preset=&amp;lt;slug&amp;gt;&lt;/code&gt;), which shares the same slugs and the same line items. Apart from the page's frame (section headings, the download block, the call to action) and the title pattern, every sentence on a template page comes from that trade's own record.&lt;/p&gt;

&lt;h2&gt;
  
  
  One typed record per trade, written three times
&lt;/h2&gt;

&lt;p&gt;Each trade is a &lt;code&gt;QuoteTemplate&lt;/code&gt;. The important part is that &lt;code&gt;en&lt;/code&gt;, &lt;code&gt;zh&lt;/code&gt; and &lt;code&gt;ja&lt;/code&gt; are three separately written &lt;code&gt;QtCopy&lt;/code&gt; objects, not one text and two translations:&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;// src/lib/quote-templates/types.ts (trimmed)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;QtCopy&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="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// the trade as people search for it&lt;/span&gt;
    &lt;span class="n"&gt;desc&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="c1"&gt;// meta description&lt;/span&gt;
    &lt;span class="n"&gt;intro&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="c1"&gt;// who sends this quote and what makes it different&lt;/span&gt;
    &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;QtItem&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;// [item, unit, qty, example price]&lt;/span&gt;
    &lt;span class="n"&gt;include&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// what a good quote for this trade spells out&lt;/span&gt;
    &lt;span class="n"&gt;mistakes&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// mistakes that cost money or the job&lt;/span&gt;
    &lt;span class="n"&gt;terms&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="c1"&gt;// deposit, balance, validity, changes&lt;/span&gt;
    &lt;span class="n"&gt;faq&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;q&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="n"&gt;a&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="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;export&lt;/span&gt; &lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;QuoteTemplate&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;slug&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="n"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;QtCategory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;downloadDepositPercent&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// when the deposit applies only to some jobs&lt;/span&gt;
    &lt;span class="n"&gt;jaReducedRateRows&lt;/span&gt;&lt;span class="o"&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="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// rows taxed at 8% in the Japanese files&lt;/span&gt;
    &lt;span class="n"&gt;en&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;QtCopy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;zh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;QtCopy&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;ja&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;QtCopy&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 boxed-lunch trade shows why translation would not work. The US page quotes 40 boxes with drinks on their own line and sales tax added on the invoice. The Taiwanese page quotes 50 boxes, asks whether the customer needs a 統編 (company tax ID) on the invoice, and warns that leaving 含稅 or 未稅 off the quote costs you 5%. The Japanese page splits the quote by consumption-tax rate, because boxed meals and tea are taxed at the reduced 8% and delivery at 10%, and asks for the invoice registration number:&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;// src/lib/quote-templates/occasions.ts (trimmed)&lt;/span&gt;
&lt;span class="n"&gt;slug&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'bento'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="n"&gt;downloadDepositPercent&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;jaReducedRateRows&lt;/span&gt;&lt;span class="p"&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;2&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;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="c1"&gt;// …&lt;/span&gt;
&lt;span class="n"&gt;ja&lt;/span&gt;&lt;span class="p"&gt;:&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="s1"&gt;'弁当・仕出し'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;items&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="s1"&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="s1"&gt;'30'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1千〜2千5百円／個'&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="s1"&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="s1"&gt;'4'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'1千2百〜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="s1"&gt;'お茶（ペットボトル 500ml）'&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="s1"&gt;'34'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'120〜200円／本'&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="s1"&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="s1"&gt;'1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'500〜3,000円'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// …&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each new trade has six line items with example prices in that market's currency, what to include, common mistakes, its payment terms and three or four FAQs. Rows stay parallel across the three languages, so the same row can become a preset in the quote tool.&lt;/p&gt;

&lt;p&gt;We went from 51 trades to 100 in one step, and the list of trades we did not add was as deliberate as the list we did. We left out:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;trades that overlapped a page we already had;&lt;/li&gt;
&lt;li&gt;licensed or regulated work, where a quote reads like professional advice;&lt;/li&gt;
&lt;li&gt;trades with thin search demand in at least two of the three markets;&lt;/li&gt;
&lt;li&gt;trades that only exist in Japan and would have no natural English or Chinese page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Measuring "too similar"
&lt;/h2&gt;

&lt;p&gt;"Every page is different" is easy to claim and hard to check by reading 300 pages. We wanted a number we could re-run on every change.&lt;/p&gt;

&lt;p&gt;The measure is simple: take the rendered &lt;code&gt;&amp;lt;main&amp;gt;&lt;/code&gt; text of each page from a local production build, remove all whitespace, cut it into overlapping 8-character pieces (shingles), and compute the Jaccard similarity of two pages' shingle sets: shared pieces divided by all distinct pieces. Character shingles need no tokenizer, so the same code works for English, Chinese and Japanese. For each page we take its nearest neighbour, the most similar other template page in the same language.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Nearest-neighbour similarity per page (8-character shingle Jaccard), mean / max:&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Language&lt;/th&gt;
&lt;th&gt;Existing 51 pages, whole page&lt;/th&gt;
&lt;th&gt;New 49 pages, whole page&lt;/th&gt;
&lt;th&gt;All 100, trade copy only&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;English&lt;/td&gt;
&lt;td&gt;0.319 / 0.367&lt;/td&gt;
&lt;td&gt;0.254 / 0.290&lt;/td&gt;
&lt;td&gt;0.029 / 0.061&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Chinese&lt;/td&gt;
&lt;td&gt;0.304 / 0.329&lt;/td&gt;
&lt;td&gt;0.258 / 0.274&lt;/td&gt;
&lt;td&gt;0.018 / 0.033&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Japanese&lt;/td&gt;
&lt;td&gt;0.327 / 0.356&lt;/td&gt;
&lt;td&gt;0.266 / 0.284&lt;/td&gt;
&lt;td&gt;0.013 / 0.032&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(The original post plots every page as a dot.)&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;The new pages are less alike than the old ones.&lt;/strong&gt; Nearest-neighbour similarity averages 0.254 for the 49 new English pages against 0.319 for the 51 existing ones; 0.258 against 0.304 in Chinese; 0.266 against 0.327 in Japanese. The highest value for any new page is 0.290 (English), below the existing pages' 0.367. The new pages are also longer: 2,822 characters of main text on average in English against 2,109, 1,190 against 964 in Chinese, 1,464 against 1,164 in Japanese.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Most of what pages share is the frame.&lt;/strong&gt; On each trade's own copy only (intro, items, what to include, mistakes, terms, FAQ), the average pair scores 0.001 to 0.009 depending on the language, and the closest pair of any two trades is 0.061. The 0.2 to 0.3 at page level is headings, the download block and the call to action. One giveaway: in Chinese, the nearest neighbour of the wallpaper, flyer-distribution and junk-removal pages is the nail-salon page. They share a layout, not a subject.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It is a regression check, not a verdict.&lt;/strong&gt; Google does not publish a similarity threshold, and a low Jaccard score does not make a page useful. What the number does is catch the failure we were afraid of: a batch of pages written from one mould, where only the trade name changes. If the new pages had come out more alike than the old ones, we would have rewritten them before shipping.&lt;/p&gt;

&lt;h2&gt;
  
  
  Spreadsheets that show their numbers before anyone opens Excel
&lt;/h2&gt;

&lt;p&gt;The Excel files are not pictures of a quote. Quantity × unit price is a live formula on every line, and subtotal, tax, total, deposit and balance follow. The first version of the generator wrote only the formulas, and Excel calculated them on open, so it looked fine in Excel.&lt;/p&gt;

&lt;p&gt;But many people never open the file in Excel. They tap it in Mail, Files or LINE on an iPhone, or preview it with Quick Look on a Mac, and those viewers do not calculate: they show what is stored in the file. In all of them every amount, the subtotal and the total were blank. The template looked broken in exactly the place people look first. Review caught it before the files shipped.&lt;/p&gt;

&lt;p&gt;The fix is to write every formula together with its result, and to tell Excel to recalculate anyway when the file is opened:&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;// scripts/build-template-downloads.ts (trimmed)&lt;/span&gt;
&lt;span class="c1"&gt;// Every formula also carries its result, so previews that do not calculate&lt;/span&gt;
&lt;span class="c1"&gt;// (iOS Files, Mail, LINE, Quick Look) still show the amounts; Excel recalculates on open.&lt;/span&gt;
&lt;span class="n"&gt;wb&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;calcProperties&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;fullCalcOnLoad&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// …&lt;/span&gt;
&lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;formula&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`IF(OR(${Q}${r}="",${P}${r}=""),"",${Q}${r}*${P}${r})`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;amount&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;That means the generator computes every number itself, the same way the formula will: per line, then per tax rate, with each market's rounding. Across the 302 workbooks there are 7,790 formula cells, and a test fails if any of them is stored without a value.&lt;/p&gt;

&lt;p&gt;The Japanese files needed one more step. Japan's consumption tax is 10%, or 8% for food and drink sold to take away or delivered, and an invoice has to show the total and the tax for each rate. Each Japanese line therefore has a rate cell, and the sheet sums and rounds down per rate:&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;b10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;formula&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`SUMIF(${rates},0.1,${range})`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'10'&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;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currency&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;t10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tax10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;formula&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="sb"&gt;`${b10}*0.1`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tax10&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currency&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;b8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;base8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;formula&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`SUMIF(${rates},0.08,${range})`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'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="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currency&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;t8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addSum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tax8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;formula&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="sb"&gt;`${b8}*0.08`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tax8&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;copy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;currency&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;For the boxed-lunch sheet, ¥40,880 of food and tea at 8% and ¥500 of delivery at 10% come to a total of ¥44,700. With every line at 10% it would have said ¥45,518, a quote a careful customer would send back.&lt;/p&gt;

&lt;p&gt;Two smaller decisions came from reading the trades' own terms. The deposit rate in each file starts at the percentage the page's terms name next to a deposit. But for 19 trades the terms take a deposit only on some jobs (ordered parts, first orders, larger jobs), so those files start at 0% through &lt;code&gt;downloadDepositPercent&lt;/code&gt;, and every file says the rate can be changed. The Word files use fixed column widths in twips rather than percentages, because Google Docs' import collapses percentage widths.&lt;/p&gt;

&lt;h2&gt;
  
  
  Generated once, byte for byte
&lt;/h2&gt;

&lt;p&gt;The 602 files (600 quotes plus two income-expense sheets, 7.15 MB) are generated by a script at commit time and committed, not built during &lt;code&gt;pnpm build&lt;/code&gt;. That keeps the spreadsheet and Word libraries out of the production image, and a page can never link a file that failed to generate.&lt;/p&gt;

&lt;p&gt;Committing generated binaries only works if regenerating them changes nothing. A zip records file dates, and the Word library gives hyperlinks random relationship ids, so we re-zip every file with fixed dates and numbered ids:&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="cm"&gt;/** Re-zip with fixed entry dates and document dates so the output is reproducible. */&lt;/span&gt;
&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;normalize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Buffer&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;ArrayBuffer&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Buffer&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;// …sort the entries, replace random rIds with rIdLink1, rIdLink2…, fix docProps dates…&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;file&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="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;date&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;FIXED_DATE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;createFolders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&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;// …&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Re-running the generator takes about 8 seconds here and leaves git clean, so a diff in &lt;code&gt;static/templates/files/&lt;/code&gt; always means the data changed. A test fails if a file no longer matches its trade's data.&lt;/p&gt;

&lt;h2&gt;
  
  
  The JavaScript nobody asked for
&lt;/h2&gt;

&lt;p&gt;Adding 49 trades almost added something we did not intend. The template page needed a few UI strings and two link helpers, and it imported them from the module's index:&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;// before&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;UI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signupHref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolHref&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'$lib/quote-templates'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// after&lt;/span&gt;
&lt;span class="c1"&gt;// From ui.ts, not the index: the index pulls every trade's copy into the page's JavaScript.&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;UI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;signupHref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolHref&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'$lib/quote-templates/ui'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The index also exports the array of every trade, so the bundler put every trade's text in all three languages into the page's client JavaScript, even though the page gets its own trade's copy from the server. With 51 trades that was already 98 KB gzip. With 100 it would have been 249 KB.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;JavaScript loaded by the English template page, KB (uncompressed / gzip -9 per file):&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Build&lt;/th&gt;
&lt;th&gt;Total&lt;/th&gt;
&lt;th&gt;Of which every trade's copy&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;51 trades, before&lt;/td&gt;
&lt;td&gt;584.9 / 221.3&lt;/td&gt;
&lt;td&gt;268.4 / 98.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100 trades, old import (built only to measure)&lt;/td&gt;
&lt;td&gt;966.3 / 369.5&lt;/td&gt;
&lt;td&gt;656.7 / 248.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100 trades, shipped&lt;/td&gt;
&lt;td&gt;316.9 / 123.5&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Chinese and Japanese pages also load their own dictionary: 695.7 → 427.3 KB and 737.6 → 469.0 KB uncompressed.&lt;/p&gt;

&lt;p&gt;We measured all three states on local production builds: the page before the expansion, the same page with 100 trades and the old import (built only to measure), and what shipped. The English page went from 221.3 KB gzip to 123.5 KB, and none of it is trade copy. The same reasoning is why the trade count shown on the hub (100) is a constant with a test that compares it to the data, instead of &lt;code&gt;QUOTE_TEMPLATES.length&lt;/code&gt;: the site dictionaries that print the count would otherwise import every trade too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Titles, hreflang and the sitemap
&lt;/h2&gt;

&lt;p&gt;Titles follow how people search in each market, and they have budgets. In Japanese, search results cut a title at about 32 characters, so the title drops "Word", then "Excel", before it would drop the trade name:&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;// src/lib/quote-templates/ui.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;JA_TITLE_SUFFIXES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'（無料・Excel・Word）'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'（無料・Excel）'&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="c1"&gt;// …&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;h1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`${t.ja.name}の見積書テンプレート`&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;suffix&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;JA_TITLE_SUFFIXES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&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;h1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&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="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="no"&gt;TITLE_MAX&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sb"&gt;`${h1}${suffix}｜NEXUPIRA`&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;Fifteen of the 100 Japanese titles drop "Word" this way. Chinese and Japanese descriptions keep each trade's own summary first and then end with the same promise, a free Excel and Word download without sign-up; the longest is 93 characters in Chinese and 107 in Japanese, under a budget of 110. Tests check every title and description against these limits.&lt;/p&gt;

&lt;p&gt;Each page has a self-referencing canonical and hreflang links to its three language versions (&lt;code&gt;en&lt;/code&gt;, &lt;code&gt;zh-Hant&lt;/code&gt;, &lt;code&gt;ja&lt;/code&gt;, with English as &lt;code&gt;x-default&lt;/code&gt;), and the sitemap carries the same alternates with a per-trade last-modified date: 300 entries. One constraint came from production routing: our edge only sends certain path prefixes to the marketing site, and everything else goes to the app. English pages have no language prefix, so every English URL has to live under one of those prefixes, here &lt;code&gt;/templates&lt;/code&gt;. A test fails if a new English URL does not.&lt;/p&gt;

&lt;p&gt;Internal links matter for 100 pages too. Each page links four related trades: its own &lt;code&gt;related&lt;/code&gt; list first, then the trades that follow it in its category, wrapping round. Before, every page in a category linked the same first four. A test checks that every trade is linked from at least one other trade page.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we know so far
&lt;/h2&gt;

&lt;p&gt;Not much yet, and we would rather say so. Before this expansion, spot checks of Japanese search results put some of our niche trade pages high quickly: #1 for OEM 見積書 テンプレート, #4 for 看板 (signage) and #4 for 自動車整備 (car servicing). The search term 見積書テンプレート itself belongs to large accounting and office-software vendors, which is why we went wide on specific trades instead. Those were early observations on a handful of the original 51 pages. The 49 new trades went live the day this post was written, so there is no search data for them yet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Prices are illustrative.&lt;/strong&gt; They are labelled as examples on every page and in every file; they are ranges we wrote, not market research.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;We have not opened the files in desktop Excel or Word.&lt;/strong&gt; They were checked with LibreOffice and macOS Quick Look, and by tests that read every workbook.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Similarity is our proxy, not Google's.&lt;/strong&gt; It catches pages cast from one mould; it says nothing about whether a page helps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No structured data for the downloads.&lt;/strong&gt; Google has no rich result for a downloadable document, so we did not add markup that would be ignored.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If you are generating pages from data
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Write a rule for when a page may exist before you write the generator,&lt;/strong&gt; and make it about content the page alone has.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Keep the data per market, not per string.&lt;/strong&gt; If two languages can share one sentence, they probably should not share one page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure similarity on the text people see, and separately on the content alone.&lt;/strong&gt; The difference between the two is your frame.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Open your generated files where your users open them.&lt;/strong&gt; A phone preview does not run formulas.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check what your page imports.&lt;/strong&gt; One import from an index file put 249 KB gzip of other pages' text on every page.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;NEXUPIRA builds AI coworkers for small businesses: when a customer asks for a price on WhatsApp, Telegram or LINE, it drafts the reply and the quote for the owner to approve, and it keeps the books and the calendar. The templates in this post are free on &lt;a href="https://nexupira.com/templates/quote?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=geo_repost&amp;amp;utm_content=programmatic-quote-templates"&gt;our quote template page&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>seo</category>
      <category>sveltekit</category>
      <category>typescript</category>
      <category>i18n</category>
    </item>
    <item>
      <title>How we took our Chinese and Japanese pages from 77 to 100 on mobile Lighthouse</title>
      <dc:creator>Jo-Tung Wu</dc:creator>
      <pubDate>Wed, 18 Nov 2026 14:03:09 +0000</pubDate>
      <link>https://dev.to/jo_tungwu_19cab1323e4b66/how-we-took-our-chinese-and-japanese-pages-from-77-to-100-on-mobile-lighthouse-1e3o</link>
      <guid>https://dev.to/jo_tungwu_19cab1323e4b66/how-we-took-our-chinese-and-japanese-pages-from-77-to-100-on-mobile-lighthouse-1e3o</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on the &lt;a href="https://nexupira.com/news/cjk-mobile-performance" rel="noopener noreferrer"&gt;NEXUPIRA engineering blog&lt;/a&gt;, with the charts and diagrams.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our marketing site is a SvelteKit app that serves the same pages in English, Traditional Chinese and Japanese. The English home page did fine on mobile Lighthouse. The Chinese and Japanese pages did not: /zh scored 86 with an LCP of 3.84 s, and /ja scored 77 with a CLS of 0.179 on top.&lt;/p&gt;

&lt;p&gt;The obvious suspect is fonts. CJK web fonts are big, Noto Sans TC alone is several megabytes spread over many subsets, and that is where we started looking too. But the main reason /ja jumped around and /zh painted its headline so late turned out to be a bug that had little to do with fonts. This post follows the investigation in order. Every number was measured, and the code is what runs on the site today, trimmed.&lt;/p&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Page&lt;/th&gt;
&lt;th&gt;Mobile score&lt;/th&gt;
&lt;th&gt;Mobile LCP (s)&lt;/th&gt;
&lt;th&gt;Mobile CLS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;/&lt;/code&gt; (English)&lt;/td&gt;
&lt;td&gt;92 → &lt;strong&gt;100&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;3.01 → &lt;strong&gt;1.66&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;0.001 → 0.001&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/zh&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;86 → &lt;strong&gt;100&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;3.84 → &lt;strong&gt;1.66&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;0 → 0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/ja&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;77 → &lt;strong&gt;100&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;3.91 → &lt;strong&gt;1.66&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;0.179 → &lt;strong&gt;0&lt;/strong&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/zh/pricing&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;93 → &lt;strong&gt;100&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;3.01 → &lt;strong&gt;1.65&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;0.003 → 0.003&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/zh/templates/quote/air-conditioning&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;91 → &lt;strong&gt;100&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;3.16 → &lt;strong&gt;1.65&lt;/strong&gt;
&lt;/td&gt;
&lt;td&gt;0 → 0&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Lighthouse 12.8, simulated mobile, local production build, median of three runs.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Figure 1, a before/after dot chart of score and LCP per page, is in the &lt;a href="https://nexupira.com/news/cjk-mobile-performance" rel="noopener noreferrer"&gt;original post&lt;/a&gt;.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;How these were measured: Lighthouse 12.8 with its default simulated mobile throttling, against a local production build, median of three runs per page, both versions on the same machine in the same session. After the release we spot-checked production: /zh and /ja both scored 97, with an LCP of 1.3 s and a CLS of 0 (one run each). We had also run Lighthouse against production before the change, but single runs were all over the place: the same /zh scored 63 on one run and 89 a few minutes later. So the before/after comparison uses the local medians.&lt;/p&gt;

&lt;h2&gt;
  
  
  The symptom: LCP was almost all render delay
&lt;/h2&gt;

&lt;p&gt;Lighthouse's LCP breakdown made the shape of the problem clear. On /zh the LCP element is the headline text, not an image, so there is no resource load phase at all. Of the 3.84 s, 0.45 s was time to first byte and the other 3.39 s (88%) was render delay. The HTML had arrived; the text just was not being painted.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;LCP breakdown, /zh, simulated mobile.&lt;/strong&gt; Before: 0.45 s TTFB + 3.39 s render delay, FCP 2.19 s, LCP 3.84 s. Before the first paint the browser also fetched the 135 KiB Noto TC stylesheet and the Latin font stylesheet at VeryHigh priority, about 50 JS modulepreloads, and ran hydration. After: 0.45 s TTFB + 1.20 s render delay, FCP 1.35 s, LCP 1.66 s; only the page CSS comes before the first paint. &lt;em&gt;(Diagram in the &lt;a href="https://nexupira.com/news/cjk-mobile-performance" rel="noopener noreferrer"&gt;original post&lt;/a&gt;.)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What was the browser doing instead? The request list in the same report:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the Google Fonts stylesheet for Noto Serif TC and Noto Sans TC, &lt;strong&gt;135 KiB&lt;/strong&gt; transferred (about 490 KiB uncompressed), at VeryHigh priority;&lt;/li&gt;
&lt;li&gt;the Google Fonts stylesheet for the Latin fonts (Newsreader, Inter, JetBrains Mono), also VeryHigh;&lt;/li&gt;
&lt;li&gt;about 50 JS &lt;code&gt;modulepreload&lt;/code&gt;s;&lt;/li&gt;
&lt;li&gt;and on a fast connection, where the JS was already there, the browser ran the whole hydration before painting the server-rendered page.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We took these apart one by one. But first, the surprising one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 1: the locale store said "en" before the page data arrived
&lt;/h2&gt;

&lt;p&gt;It started with a small thing we noticed: while /ja loaded, the flag in the language switcher went Japan → US → Japan.&lt;/p&gt;

&lt;p&gt;The site's &lt;code&gt;locale&lt;/code&gt; is a store derived from SvelteKit's &lt;code&gt;$page&lt;/code&gt;. The server load decides the language and puts it in the page data. The problem was the window at the start of hydration, before the first page data was there: the store had no value, so it answered its default, &lt;code&gt;'en'&lt;/code&gt;. And a subscriber to that store keeps &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt; in sync.&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;// before&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;derived&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Locale&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;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$page&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&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;locale&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;raw&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'zh'&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'zh'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'ja'&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'ja'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'en'&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;So for a few hundred milliseconds, &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt; on /zh and /ja said &lt;code&gt;en&lt;/code&gt;. Our CJK fonts are switched through CSS variables keyed on selectors like &lt;code&gt;html[lang="ja"]&lt;/code&gt;, and the headline size depends on the language too. During that window the headline was laid out again in the English font and size, then switched back and laid out a third time when the page data arrived:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;on /ja, the two reflows were a 0.179 layout shift (0.094 on desktop);&lt;/li&gt;
&lt;li&gt;on /zh, the largest text block was repainted when it switched back, pushing LCP later;&lt;/li&gt;
&lt;li&gt;language-dependent blocks hydrated in English, then flipped back to Chinese or Japanese.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The locale flash on /ja.&lt;/strong&gt; Server HTML: &lt;code&gt;&amp;lt;html lang="ja"&amp;gt;&lt;/code&gt;, Japanese font → JS starts, no page data yet: the store answers &lt;code&gt;en&lt;/code&gt;, &lt;code&gt;&amp;lt;html lang="en"&amp;gt;&lt;/code&gt;, the headline reflows in the English font and size → page data arrives: back to &lt;code&gt;ja&lt;/code&gt;, reflows again. CLS 0.179. After the fix &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt; stays &lt;code&gt;ja&lt;/code&gt; throughout: CLS 0. &lt;em&gt;(Diagram in the &lt;a href="https://nexupira.com/news/cjk-mobile-performance" rel="noopener noreferrer"&gt;original post&lt;/a&gt;.)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The fix is small: with no page data yet, read the language from the URL. The server already decides the language from the URL prefix, so using the same rule keeps both sides in agreement.&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;// after (src/lib/i18n/locale.ts)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;derived&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$page&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Locale&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;raw&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$page&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;locale&lt;/span&gt;&lt;span class="o"&gt;?:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&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;locale&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;raw&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'zh'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'ja'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'en'&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;raw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="c1"&gt;// No page data yet: the URL already says which language the page is.&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;browser&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;localeFromPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;location&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="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'en'&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;That alone took the /ja CLS to zero. The lesson: &lt;strong&gt;on a multilingual SSR site, ask of every default value whether it can differ from what the server rendered during early hydration.&lt;/strong&gt; &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt; is not only for accessibility and SEO; through CSS it can swap your fonts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 2: a 135 KiB font stylesheet at the highest priority
&lt;/h2&gt;

&lt;p&gt;We load the CJK fonts from Google Fonts with &lt;code&gt;display=optional&lt;/code&gt;, already split per language: /zh loads only TC, /ja only JP, English pages none. The issue was how. To avoid blocking render, the stylesheet was a &lt;code&gt;rel="preload" as="style"&lt;/code&gt; that a script turned into a stylesheet once it loaded:&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;// before (src/lib/seo/fonts.ts)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`&amp;lt;link id="nx-fonts-cjk" rel="preload" as="style" href="${href}" /&amp;gt;&amp;lt;noscript&amp;gt;&amp;lt;link rel="stylesheet" href="${href}" /&amp;gt;&amp;lt;/noscript&amp;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;preload&lt;/code&gt; does not block rendering, but it is fetched at the highest priority. A Google Fonts CJK stylesheet lists hundreds of &lt;code&gt;unicode-range&lt;/code&gt; subsets, so it is 135 KiB over the wire on its own. It and the roughly 350 KB of font files it went on to start were fetched at top priority before the first paint, sharing a phone's connection with the CSS the page actually needed to paint.&lt;/p&gt;

&lt;p&gt;The change: no font stylesheet goes in before the first paint. The Latin fonts are now self-hosted (the exact Google Fonts files and &lt;code&gt;@font-face&lt;/code&gt; rules, &lt;code&gt;display=swap&lt;/code&gt;), so English pages need no third-party connection for fonts. CJK stays on Google Fonts, split per language, with &lt;code&gt;display=optional&lt;/code&gt;: if the font is not ready almost at once, this page view keeps the system CJK font and never swaps late, so there is no late LCP; the font is cached for the next page. Our CSS variables put system CJK fonts ahead of Noto, so devices that have their own CJK fonts never download them at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 3: when to add the font stylesheets, and a measured trade-off
&lt;/h2&gt;

&lt;p&gt;The server puts both stylesheets into an inert &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt;, which the browser does not fetch, plus a &lt;code&gt;&amp;lt;noscript&amp;gt;&lt;/code&gt; copy for visitors without JavaScript:&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;// src/lib/seo/fonts.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;links&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;media&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sheets&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;href&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;`&amp;lt;link rel="stylesheet"${media} href="${href}" /&amp;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="k"&gt;return&lt;/span&gt; &lt;span class="sb"&gt;`${preconnect}&amp;lt;template id="nx-font-sheets"&amp;gt;${links(' media="print"')}&amp;lt;/template&amp;gt;&amp;lt;noscript&amp;gt;${links('')}&amp;lt;/noscript&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A small inline script in &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt; waits for &lt;code&gt;first-contentful-paint&lt;/code&gt; and then clones the links out of the template. &lt;code&gt;media="print"&lt;/code&gt; makes the browser fetch them at the lowest priority; they switch to &lt;code&gt;all&lt;/code&gt; once loaded. Our CSP does not allow inline &lt;code&gt;onload="…"&lt;/code&gt; attributes, so the listeners are attached in JS.&lt;/p&gt;

&lt;p&gt;Review of the first version caught a regression: first visits were fine, but on &lt;strong&gt;repeat&lt;/strong&gt; visits, with the fonts already cached, every page still painted first in the fallback fonts (Georgia and system sans) and then swapped to Newsreader and Inter. A flash on every page.&lt;/p&gt;

&lt;p&gt;The fix is a localStorage flag. Once the Latin stylesheet has loaded, the script records &lt;code&gt;nx-font-sheets-seen&lt;/code&gt;. On the next visit it adds that stylesheet immediately with &lt;code&gt;blocking="render"&lt;/code&gt;, so the first paint already uses the cached fonts:&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;// src/app.html (excerpt)&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;early&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// …clone each &amp;lt;link&amp;gt; out of the &amp;lt;template&amp;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;early&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;own&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;media&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'all'&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;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'blocking'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'render'&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="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;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'load'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&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;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;media&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'all'&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;once&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="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;// …and set nx-font-sheets-seen once the self-hosted sheet has loaded&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;seen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;start&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="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PerformanceObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;obs&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;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getEntriesByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'first-contentful-paint'&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="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;obs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&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;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&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="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;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'paint'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;buffered&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="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;start&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// a background tab never paints&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this part we used throttled runs in real Chromium rather than Lighthouse, first visit (cold) and repeat visit (warm):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Build&lt;/th&gt;
&lt;th&gt;Cold FCP (/ · /zh)&lt;/th&gt;
&lt;th&gt;Cold: fonts at FCP&lt;/th&gt;
&lt;th&gt;Warm FCP (/ · /zh)&lt;/th&gt;
&lt;th&gt;Warm: fonts at FCP&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Before&lt;/td&gt;
&lt;td&gt;708 / 700 ms&lt;/td&gt;
&lt;td&gt;0/3&lt;/td&gt;
&lt;td&gt;356 / 280 ms&lt;/td&gt;
&lt;td&gt;3/3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;First version (deferred only)&lt;/td&gt;
&lt;td&gt;660 / 628 ms&lt;/td&gt;
&lt;td&gt;0/3&lt;/td&gt;
&lt;td&gt;308 / 340 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;0/3 (flash)&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Final (repeat-visit flag)&lt;/td&gt;
&lt;td&gt;632 / 608 ms&lt;/td&gt;
&lt;td&gt;0/3&lt;/td&gt;
&lt;td&gt;312 / 328 ms&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;3/3&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Inlined &lt;code&gt;@font-face&lt;/code&gt; (tried, not kept)&lt;/td&gt;
&lt;td&gt;704 / 612 ms&lt;/td&gt;
&lt;td&gt;0/3&lt;/td&gt;
&lt;td&gt;356 / 340 ms&lt;/td&gt;
&lt;td&gt;3/3&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Real Chromium, not simulated: 150 ms RTT, 1.6 Mbps, 4x CPU slowdown, 412 px viewport, three runs. Warm = second load of the same page with the cache intact. "Fonts at FCP" = Newsreader and Inter were loaded when first contentful paint was reported.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The last row is the obvious alternative: inline the &lt;code&gt;@font-face&lt;/code&gt; rules in every page. Repeat visits are fine that way too, but on a first visit the browser then fetches the font files before the first paint, and mobile Lighthouse dropped from 100 to 78 on &lt;code&gt;/&lt;/code&gt; (LCP 1.85 s → 4.35 s) and from 99 to 87 on &lt;code&gt;/zh&lt;/code&gt;. So we kept the flag.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trap 4: 50 modulepreloads, and hydration before the first paint
&lt;/h2&gt;

&lt;p&gt;By default SvelteKit sends a &lt;code&gt;modulepreload&lt;/code&gt; for each JS module the page uses. On our home page that was about 50, all requested at high priority before the first paint, sharing the connection with the CSS the paint was waiting for. The pages are server-rendered and display without JS, so we keep preloading CSS only:&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;// src/hooks.server.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;response&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;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;preload&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;type&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="kd"&gt;type&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'js'&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="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The entry scripts at the end of &lt;code&gt;&amp;lt;body&amp;gt;&lt;/code&gt; still load at once, and each route's modules are fetched together when hydration starts.&lt;/p&gt;

&lt;p&gt;The other half is when hydration runs. When the JS is already at hand (a repeat visit, a fast connection), the browser ran the whole hydration before painting the server-rendered page. SvelteKit's &lt;code&gt;hooks.client.ts&lt;/code&gt; can export an &lt;code&gt;init&lt;/code&gt; function, and hydration does not start until it resolves, so we make it wait for the first paint:&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;// src/hooks.client.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;ClientInit&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;=&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;void&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="n"&gt;resolve&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;go&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;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&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;try&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="nc"&gt;PerformanceObserver&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;supportedEntryTypes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'paint'&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="nb"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'no paint timing'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PerformanceObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;observer&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;list&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getEntriesByName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'first-contentful-paint'&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="p"&gt;{&lt;/span&gt;
                    &lt;span class="n"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;disconnect&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;go&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="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'paint'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;buffered&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="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nf"&gt;requestAnimationFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;go&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;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1500&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 &lt;code&gt;setTimeout(resolve, 1500)&lt;/code&gt; is for background tabs: they never paint, and they should not wait forever to hydrate.&lt;/p&gt;

&lt;p&gt;The risk with later hydration is slower interaction. With the same throttling we measured when each page finished hydrating: &lt;code&gt;/&lt;/code&gt; at 2.77 s (2.75 s before) and &lt;code&gt;/zh&lt;/code&gt; at 3.16 s (4.25 s before). The English home page is the same within noise, and the Chinese page is hydrated more than a second sooner, because its resources no longer fight each other.&lt;/p&gt;

&lt;p&gt;One side effect: the &lt;code&gt;load&lt;/code&gt; event can now fire before hydration, so end-to-end tests cannot click a JS control right after &lt;code&gt;goto&lt;/code&gt;. The root layout sets &lt;code&gt;&amp;lt;html data-hydrated&amp;gt;&lt;/code&gt; on mount, and tests that click wait for it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two small changes that paid off
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Logos as WebP at display size.&lt;/strong&gt; The home page's integration marquee and task icons used the original logo files (up to 3301 px wide, 8–57 KB each) shown at most 44 px tall. As WebP at most 96 px tall and 300 px wide (2–3x the shown size), the 16 files went from about 438 KB to about 37 KB. &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; match the new files, so the reserved shape is unchanged.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No article bodies in the home bundle.&lt;/strong&gt; A home page section imported &lt;code&gt;formatDate&lt;/code&gt; from &lt;code&gt;$lib/content&lt;/code&gt;, which pulled the &lt;code&gt;marked&lt;/code&gt; Markdown parser (36 KB) into the home page. And the &lt;code&gt;?raw&lt;/code&gt; glob that lists news titles on the home page shipped every article body in all three languages. &lt;code&gt;formatDate&lt;/code&gt; moved to its own file, and a small Vite plugin answers &lt;code&gt;?frontmatter&lt;/code&gt; imports with the leading &lt;code&gt;---&lt;/code&gt; block only:&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;// vite.config.ts&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;frontMatterOnly&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="nc"&gt;Plugin&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="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'nx-front-matter-only'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;enforce&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'pre'&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="n"&gt;id&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;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&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="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;'frontmatter'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;endsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.md'&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="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addWatchFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&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;block&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'utf8'&lt;/span&gt;&lt;span class="p"&gt;)&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;n&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;\&lt;span class="n"&gt;s&lt;/span&gt;\&lt;span class="no"&gt;S&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;*?&lt;/span&gt;\&lt;span class="n"&gt;n&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="sb"&gt;`export default ${JSON.stringify(block ? block[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="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;Home route JS went from 470 KB to 409 KB uncompressed.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we did not do, and the limits of these numbers
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;blocking="render"&lt;/code&gt; is Chromium-only.&lt;/strong&gt; Safari and Firefox still add the stylesheet at once on repeat visits, but without blocking render, so a very brief font swap is still possible there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The CJK fonts are still on Google Fonts.&lt;/strong&gt; Lighthouse still lists that stylesheet as unused and unminified CSS. It now loads after the first paint on a first visit, but we did not self-host a CJK subset.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If the cache is evicted but the flag survives&lt;/strong&gt;, the first paint waits for one same-origin request (about 2 KB).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No fallback-font metric overrides&lt;/strong&gt; (&lt;code&gt;size-adjust&lt;/code&gt; and friends). The /ja CLS came from the locale flash; the font swap itself measures about 0.0001.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The number of JS modules did not go down.&lt;/strong&gt; We tried Rollup's &lt;code&gt;experimentalMinChunkSize&lt;/code&gt;, and it dragged a lazily loaded package into the eager graph, so we removed the preloads instead. About 47 small modules still load during hydration, just after the first paint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lab numbers are not real users.&lt;/strong&gt; The table is simulated mobile against a local production build (HTTP/1.1, localhost); the production 97 and 1.3 s are single spot checks. Field Core Web Vitals need weeks of real traffic before they mean much.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  If you run a Chinese or Japanese site
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read the LCP breakdown first.&lt;/strong&gt; If the LCP element is text and render delay is most of it, the problem is not slow downloads; something is blocking or competing with the paint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Check every value that depends on page data during early hydration&lt;/strong&gt;, especially a locale that ends up in &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt;. The quick test: load a non-English page with slow throttling and watch the language switcher or &lt;code&gt;&amp;lt;html lang&amp;gt;&lt;/code&gt; for a flicker.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;rel="preload"&lt;/code&gt; is not "load quietly", it is "load first".&lt;/strong&gt; If the first screen does not need it, do not preload it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Google Fonts CJK stylesheet is over 100 KB by itself.&lt;/strong&gt; Split it per language, use &lt;code&gt;display=optional&lt;/code&gt;, and add it after the first paint.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Measure every fix that feels obviously better.&lt;/strong&gt; Inlining &lt;code&gt;@font-face&lt;/code&gt; looked simpler; measured, it took first-visit LCP from 1.85 s to 4.35 s.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;NEXUPIRA builds AI coworkers for small businesses: when a customer asks for a price on WhatsApp, Telegram or LINE, it drafts the reply and the quote for the owner to approve, and it keeps the books and the calendar. This post was about its website; &lt;a href="https://nexupira.com/?utm_source=dev.to&amp;amp;utm_medium=referral&amp;amp;utm_campaign=geo_repost&amp;amp;utm_content=cjk-mobile-performance"&gt;take a look&lt;/a&gt; if you are curious.&lt;/p&gt;

</description>
      <category>webperf</category>
      <category>svelte</category>
      <category>i18n</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
