[{"data":1,"prerenderedAt":3160},["ShallowReactive",2],{"\u002Farticles\u002Fspa-hash-seo-prerender":3},{"id":4,"title":5,"body":6,"date":3144,"description":3145,"extension":3146,"head":3147,"image":3148,"meta":3149,"navigation":1281,"ogImage":3147,"path":3150,"rating":3151,"readingTime":3152,"robots":3147,"schemaOrg":3147,"seo":3153,"sitemap":3154,"stem":3155,"tags":3156,"__hash__":3159},"articles_en\u002Farticles\u002Fspa-hash-seo-prerender.md","One HTML File, Two Apps: Making a Hash-Routed SPA's Home Page Crawlable Without Touching the Router",{"type":7,"value":8,"toc":3123},"minimark",[9,30,72,80,87,220,239,252,298,301,351,361,365,368,399,405,424,430,436,522,525,529,537,591,594,624,634,678,685,689,694,701,1070,1073,1122,1125,1186,1193,1197,1211,1626,1629,1713,1716,1773,1777,1988,2007,2026,2030,2034,2037,2043,2108,2115,2119,2129,2174,2188,2199,2246,2249,2253,2264,2267,2282,2285,2289,2311,2324,2330,2437,2443,2453,2460,2464,2477,2494,2500,2591,2601,2693,2696,2707,2711,2714,2729,2891,2898,2901,2987,2994,2998,3001,3006,3030,3035,3081,3085,3120],[10,11,12,13,17,18,20,21,25,26,29],"p",{},"\"Just get rid of the ",[14,15,16],"code",{},"#"," in the URL\" sounds like a one-line router change. It isn't, and the ",[14,19,16],{}," turned out not to be the real problem anyway. ",[22,23,24],"strong",{},"Crawlers couldn't read our content because the HTML didn't contain any."," On top of that, giving the home page a clean URL runs into a constraint that's easy to miss: ",[22,27,28],{},"a domain's root path can only serve one file",". This post is about how I got a marketing home page, full text and all, in front of search engines without changing how the admin app routes.",[31,32,33,38],"note",{},[10,34,35],{},[22,36,37],{},"The problem at a glance",[39,40,41,52,62],"ul",{},[42,43,44,47,48,51],"li",{},[22,45,46],{},"Symptom",": A Vue 3 + Vite admin app with hash routing. The marketing home page is just another route in that app, at ",[14,49,50],{},"https:\u002F\u002Fwww.example.com\u002F#\u002Flanding\u002Fhome",". We wanted it to show up in search, but a crawler hitting the domain root got a 4 kB shell with a loading spinner and nothing else.",[42,53,54,57,58,61],{},[22,55,56],{},"Constraints",": No admin URL could change. That includes ",[14,59,60],{},"\u002F#\u002Flogin",", short links already sent out by SMS, and third-party login callbacks. The test environment also lives in a subdirectory of a shared domain, where a server-side fallback isn't available.",[42,63,64,67,68,71],{},[22,65,66],{},"What you'll take away",": How I chose between three options, a reusable way to serve two apps from one ",[14,69,70],{},"index.html",", the skeleton of a build-time prerender plugin, and four problems that only show up once you actually ship this.",[73,74,76,77,79],"h2",{"id":75},"_1-where-it-started-is-really-the-problem","1. Where It Started: Is ",[14,78,16],{}," Really the Problem?",[10,81,82,83,86],{},"Let's look at what a crawler actually gets. A request to ",[14,84,85],{},"https:\u002F\u002Fwww.example.com\u002F"," came back with roughly this:",[88,89,94],"pre",{"className":90,"code":91,"language":92,"meta":93,"style":93},"language-html shiki shiki-themes github-light github-dark github-dark","\u003Chead>\n  \u003Ctitle>Admin\u003C\u002Ftitle>\n\u003C\u002Fhead>\n\u003Cbody>\n  \u003Cdiv id=\"app\">\u003C!-- just a loading spinner -->\u003C\u002Fdiv>\n  \u003Cscript type=\"module\" src=\".\u002Fassets\u002Fjs\u002Findex-xxxx.js\">\u003C\u002Fscript>\n\u003C\u002Fbody>\n","html","",[14,95,96,112,128,138,148,180,211],{"__ignoreMap":93},[97,98,101,105,109],"span",{"class":99,"line":100},"line",1,[97,102,104],{"class":103},"slsVL","\u003C",[97,106,108],{"class":107},"sByVh","head",[97,110,111],{"class":103},">\n",[97,113,115,118,121,124,126],{"class":99,"line":114},2,[97,116,117],{"class":103},"  \u003C",[97,119,120],{"class":107},"title",[97,122,123],{"class":103},">Admin\u003C\u002F",[97,125,120],{"class":107},[97,127,111],{"class":103},[97,129,131,134,136],{"class":99,"line":130},3,[97,132,133],{"class":103},"\u003C\u002F",[97,135,108],{"class":107},[97,137,111],{"class":103},[97,139,141,143,146],{"class":99,"line":140},4,[97,142,104],{"class":103},[97,144,145],{"class":107},"body",[97,147,111],{"class":103},[97,149,151,153,156,160,163,167,170,174,176,178],{"class":99,"line":150},5,[97,152,117],{"class":103},[97,154,155],{"class":107},"div",[97,157,159],{"class":158},"shcOC"," id",[97,161,162],{"class":103},"=",[97,164,166],{"class":165},"sfrk1","\"app\"",[97,168,169],{"class":103},">",[97,171,173],{"class":172},"sCsY4","\u003C!-- just a loading spinner -->",[97,175,133],{"class":103},[97,177,155],{"class":107},[97,179,111],{"class":103},[97,181,183,185,188,191,193,196,199,201,204,207,209],{"class":99,"line":182},6,[97,184,117],{"class":103},[97,186,187],{"class":107},"script",[97,189,190],{"class":158}," type",[97,192,162],{"class":103},[97,194,195],{"class":165},"\"module\"",[97,197,198],{"class":158}," src",[97,200,162],{"class":103},[97,202,203],{"class":165},"\".\u002Fassets\u002Fjs\u002Findex-xxxx.js\"",[97,205,206],{"class":103},">\u003C\u002F",[97,208,187],{"class":107},[97,210,111],{"class":103},[97,212,214,216,218],{"class":99,"line":213},7,[97,215,133],{"class":103},[97,217,145],{"class":107},[97,219,111],{"class":103},[10,221,222,223,226,227,230,231,234,235,238],{},"No body text, no ",[14,224,225],{},"description",", no ",[14,228,229],{},"og:"," tags for link previews. ",[14,232,233],{},"robots.txt"," and ",[14,236,237],{},"sitemap.xml"," returned the very same HTML, because the static host serves the home page for any path that doesn't exist.",[10,240,241,242,244,245,251],{},"Now for the ",[14,243,16],{},". ",[22,246,247,248,250],{},"Everything after the ",[14,249,16],{}," in a URL (the fragment) never leaves the browser."," It isn't sent to the server at all. That has two consequences:",[253,254,255,273],"ol",{},[42,256,257,258,261,262,264,265,268,269,272],{},"As far as a crawler is concerned, ",[14,259,260],{},"\u002F#\u002Flanding\u002Fhome",", ",[14,263,60],{},", and ",[14,266,267],{},"\u002F#\u002Fanything"," are all the same URL: ",[14,270,271],{},"\u002F",". Pages behind hash routing can't be indexed individually.",[42,274,275,281,282,285,286,288,289,291,292,294,295,297],{},[22,276,277,278,280],{},"The server can't do anything about the ",[14,279,16],{},"."," The first thing I asked was whether ops could just add a rule. They can't. All ops can control is what a given path returns, say a 302 from ",[14,283,284],{},"\u002Flanding\u002Fhome"," to ",[14,287,260],{},". The link you share looks clean, but the ",[14,290,16],{}," is back in the address bar the moment it loads, and a crawler following the redirect drops the fragment and indexes ",[14,293,271],{}," anyway. The front-end router puts the ",[14,296,16],{}," there, so the front end has to take it away.",[10,299,300],{},"So this is really two separate problems tangled together:",[302,303,304,323],"table",{},[305,306,307],"thead",{},[308,309,310,314,317],"tr",{},[311,312,313],"th",{},"Problem",[311,315,316],{},"What causes it",[311,318,319,320,322],{},"Does dropping the ",[14,321,16],{}," fix it?",[324,325,326,338],"tbody",{},[308,327,328,332,335],{},[329,330,331],"td",{},"The home page has no clean URL of its own",[329,333,334],{},"How hash-routed URLs are shaped",[329,336,337],{},"Yes",[308,339,340,343,346],{},[329,341,342],{},"Crawlers can't read the body text",[329,344,345],{},"Everything is rendered client-side",[329,347,348],{},[22,349,350],{},"No",[10,352,353,354,357,358,360],{},"Googlebot does run JavaScript, but rendering happens in a deferred second pass that's slow and not guaranteed. Link-preview scrapers, and most crawlers that only read raw HTML, don't run JS at all. ",[22,355,356],{},"The second problem is the one that matters for SEO."," Dropping the ",[14,359,16],{}," is just a prerequisite.",[73,362,364],{"id":363},"_2-three-options-and-one-constraint-you-cant-get-around","2. Three Options and One Constraint You Can't Get Around",[10,366,367],{},"There were three obvious ways to go.",[10,369,370,373,374,377,378,381,382,234,385,387,388,391,392,394,395,398],{},[22,371,372],{},"Option 1: move the whole app to history mode."," Swap ",[14,375,376],{},"createWebHashHistory"," for ",[14,379,380],{},"createWebHistory",", and URLs turn into ",[14,383,384],{},"\u002Flogin",[14,386,284],{},". The catch is that every admin URL changes, so old links need a compatibility shim. The relative asset base ",[14,389,390],{},".\u002F"," has to become absolute, or ",[14,393,284],{}," will go looking for ",[14,396,397],{},"\u002Flanding\u002Fassets\u002F...",". And every environment's static host needs a 404 fallback, which my test environment, tucked into a subdirectory of a shared domain, can't have.",[10,400,401,404],{},[22,402,403],{},"Option 2: pull the home page out into its own project on the same domain."," This is the cleanest way to organize the code. But it runs straight into the constraint:",[406,407,408],"warning",{},[10,409,410,413,414,416,417,419,420,423],{},[22,411,412],{},"The root path can only serve one file."," The admin URL is ",[14,415,60],{},", which the server sees as plain ",[14,418,271],{}," because the fragment never arrives. So you can't have both \"the home page owns the domain root\" and \"admin URLs stay the same\" through deployment alone. Either the home page gives up the root and moves into a subdirectory, leaving the admin shell as the site's front page, or the admin app moves to ",[14,421,422],{},"\u002Fapp\u002F"," and every one of its URLs changes. The server simply can't tell someone who came for the home page from someone who came to log in.",[10,425,426,429],{},[22,427,428],{},"Option 3: use history mode for the home page only and leave everything else on hash."," You'd pick the router instance at startup based on the URL. It works, but now a single app runs two routing modes and your navigation guards have to handle crossing between them. It also only fixes the URL, not the missing content.",[10,431,432,433],{},"Every option came with a cost I wasn't willing to pay. But turn that constraint around and it becomes the answer: ",[22,434,435],{},"if the root path can only serve one file, make that one file do two jobs.",[302,437,438,453],{},[305,439,440],{},[308,441,442,444,447,450],{},[311,443],{},[311,445,446],{},"Full history mode",[311,448,449],{},"Separate project",[311,451,452],{},"One HTML, two apps",[324,454,455,473,487,499,511],{},[308,456,457,460,464,469],{},[329,458,459],{},"Home page URL",[329,461,462],{},[14,463,284],{},[329,465,466,468],{},[14,467,271],{}," or a subdirectory, not both",[329,470,471],{},[14,472,271],{},[308,474,475,478,481,484],{},[329,476,477],{},"Admin URLs",[329,479,480],{},"All change",[329,482,483],{},"Either unchanged or all change",[329,485,486],{},"Unchanged",[308,488,489,492,494,497],{},[329,490,491],{},"Needs a server fallback",[329,493,337],{},[329,495,496],{},"Partly",[329,498,350],{},[308,500,501,504,507,509],{},[329,502,503],{},"Crawlers can read the body",[329,505,506],{},"No, still client-rendered",[329,508,337],{},[329,510,337],{},[308,512,513,516,518,520],{},[329,514,515],{},"Home page and admin ship independently",[329,517,350],{},[329,519,337],{},[329,521,350],{},[10,523,524],{},"That last row is what it costs. More on that in section 8.",[73,526,528],{"id":527},"_3-the-approach-one-html-file-two-apps","3. The Approach: One HTML File, Two Apps",[10,530,531,532],{},"The whole idea fits in a sentence: ",[22,533,534,536],{},[14,535,70],{}," ships with the home page's complete static content already in it, and a tiny inline script at the very top checks the hash in the address bar to decide whether this page load should run the home page code or the admin code.",[88,538,542],{"className":539,"code":540,"language":541,"meta":93,"style":93},"language-mermaid shiki shiki-themes github-light github-dark github-dark","flowchart TD\n    R[\"Request \u002F (same request for any hash)\"] --> H[\"index.html\u003Cbr>contains the home page's static HTML\"]\n    H --> S{\"Inline boot script\u003Cbr>checks location.hash\"}\n    S -- \"empty, #\u002F, #\u002Flanding\u002Fhome\" --> L[\"Load the home page entry\u003Cbr>hydrate the existing HTML\"]\n    S -- \"any other #\u002Fxxx\" --> A[\"Remove the home page content\u003Cbr>load the admin entry, untouched\"]\n    L --> LR[\"Address bar: \u002F\u003Cbr>only the home page's JS and CSS\"]\n    A --> AR[\"Address bar: \u002F#\u002Flogin\u003Cbr>behaves exactly as before\"]\n    style S fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n    style H fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n","mermaid",[14,543,544,549,554,559,564,569,574,579,585],{"__ignoreMap":93},[97,545,546],{"class":99,"line":100},[97,547,548],{},"flowchart TD\n",[97,550,551],{"class":99,"line":114},[97,552,553],{},"    R[\"Request \u002F (same request for any hash)\"] --> H[\"index.html\u003Cbr>contains the home page's static HTML\"]\n",[97,555,556],{"class":99,"line":130},[97,557,558],{},"    H --> S{\"Inline boot script\u003Cbr>checks location.hash\"}\n",[97,560,561],{"class":99,"line":140},[97,562,563],{},"    S -- \"empty, #\u002F, #\u002Flanding\u002Fhome\" --> L[\"Load the home page entry\u003Cbr>hydrate the existing HTML\"]\n",[97,565,566],{"class":99,"line":150},[97,567,568],{},"    S -- \"any other #\u002Fxxx\" --> A[\"Remove the home page content\u003Cbr>load the admin entry, untouched\"]\n",[97,570,571],{"class":99,"line":182},[97,572,573],{},"    L --> LR[\"Address bar: \u002F\u003Cbr>only the home page's JS and CSS\"]\n",[97,575,576],{"class":99,"line":213},[97,577,578],{},"    A --> AR[\"Address bar: \u002F#\u002Flogin\u003Cbr>behaves exactly as before\"]\n",[97,580,582],{"class":99,"line":581},8,[97,583,584],{},"    style S fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n",[97,586,588],{"class":99,"line":587},9,[97,589,590],{},"    style H fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n",[10,592,593],{},"That keeps all three audiences happy at once:",[39,595,596,605,618],{},[42,597,598,601,602,604],{},[22,599,600],{},"Crawlers"," request ",[14,603,271],{}," and get HTML with body text, a title, and a description. Whether they run JS no longer matters.",[42,606,607,610,611,613,614,617],{},[22,608,609],{},"Home page visitors"," see a clean ",[14,612,271],{}," in the address bar. The home page entry never loads vue-router, and the hash router was the only thing adding ",[14,615,616],{},"#\u002F"," in the first place.",[42,619,620,623],{},[22,621,622],{},"Admin users"," notice nothing. Hash routing, the deploy directory, and every link out in the wild stay exactly as they were.",[10,625,626,627,630,631,633],{},"So where does the static content come from? At ",[22,628,629],{},"build time",", I render the home page component once with Vue's server renderer and write the result into the built ",[14,632,70],{},":",[88,635,637],{"className":539,"code":636,"language":541,"meta":93,"style":93},"flowchart LR\n    C[\"Client build\u003Cbr>vite build\"] --> W[\"Output written\u003Cbr>dist\u002Findex.html, container empty\"]\n    W --> S[\"SSR build\u003Cbr>home page entry only\"]\n    S --> R[\"renderToString\u003Cbr>home page HTML\"]\n    R --> P[\"Fix asset URLs\u003Cbr>write back to dist\u002Findex.html\"]\n    P --> O[\"Generate robots.txt\u003Cbr>sitemap.xml\"]\n    style S fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n    style R fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n",[14,638,639,644,649,654,659,664,669,673],{"__ignoreMap":93},[97,640,641],{"class":99,"line":100},[97,642,643],{},"flowchart LR\n",[97,645,646],{"class":99,"line":114},[97,647,648],{},"    C[\"Client build\u003Cbr>vite build\"] --> W[\"Output written\u003Cbr>dist\u002Findex.html, container empty\"]\n",[97,650,651],{"class":99,"line":130},[97,652,653],{},"    W --> S[\"SSR build\u003Cbr>home page entry only\"]\n",[97,655,656],{"class":99,"line":140},[97,657,658],{},"    S --> R[\"renderToString\u003Cbr>home page HTML\"]\n",[97,660,661],{"class":99,"line":150},[97,662,663],{},"    R --> P[\"Fix asset URLs\u003Cbr>write back to dist\u002Findex.html\"]\n",[97,665,666],{"class":99,"line":182},[97,667,668],{},"    P --> O[\"Generate robots.txt\u003Cbr>sitemap.xml\"]\n",[97,670,671],{"class":99,"line":213},[97,672,584],{},[97,674,675],{"class":99,"line":581},[97,676,677],{},"    style R fill:#E1EDFC,stroke:#3B6FD4,stroke-width:2px\n",[10,679,680,681,684],{},"To be clear, this isn't SSR at runtime. There's no Node server, and the output is still a folder of static files that gets uploaded to object storage like before. This is usually called ",[22,682,683],{},"prerendering",", or static generation.",[73,686,688],{"id":687},"_4-implementation","4. Implementation",[690,691,693],"h3",{"id":692},"_41-the-boot-script","4.1 The boot script",[10,695,696,697,700],{},"It sits in ",[14,698,699],{},"\u003Chead>"," and has to be inline and synchronous, since it needs to finish before the browser paints anything:",[88,702,704],{"className":90,"code":703,"language":92,"meta":93,"style":93},"\u003Cscript>\n  (function () {\n    var hash = location.hash;\n    var path = hash.replace(\u002F^#\u002F, \"\").split(\"?\")[0].replace(\u002F\\\u002F+$\u002F, \"\");\n    var isAdminHash = \u002F^#\\\u002F\u002F.test(hash) && path !== \"\" && path !== \"\u002Flanding\" && path !== \"\u002Flanding\u002Fhome\";\n    \u002F\u002F An existing short link, \u002Fm, only gets here because unknown paths fall back to index.html. Hand it back to admin\n    var isShortEntry = \u002F\\\u002Fm$\u002F.test(location.pathname);\n    var landing = !isAdminHash && !isShortEntry;\n    window.__LANDING__ = landing;\n    document.documentElement.className += landing ? \" boot-landing\" : \" boot-admin\";\n    if (landing) {\n      \u002F\u002F Tidy old URLs like \u002F#\u002Flanding\u002Fhome and \u002F#\u002F into a clean one, without a reload\n      if (\u002F^#\\\u002F\u002F.test(hash)) history.replaceState(history.state, \"\", location.pathname + location.search);\n    } else {\n      document.title = \"Admin\";\n    }\n  })();\n\u003C\u002Fscript>\n",[14,705,706,714,726,739,815,876,881,909,931,941,966,975,981,1024,1036,1049,1055,1061],{"__ignoreMap":93},[97,707,708,710,712],{"class":99,"line":100},[97,709,104],{"class":103},[97,711,187],{"class":107},[97,713,111],{"class":103},[97,715,716,719,723],{"class":99,"line":114},[97,717,718],{"class":103},"  (",[97,720,722],{"class":721},"so5gQ","function",[97,724,725],{"class":103}," () {\n",[97,727,728,731,734,736],{"class":99,"line":130},[97,729,730],{"class":721},"    var",[97,732,733],{"class":103}," hash ",[97,735,162],{"class":721},[97,737,738],{"class":103}," location.hash;\n",[97,740,741,743,746,748,751,754,757,759,762,765,767,769,772,775,778,780,783,786,790,793,795,797,799,803,806,808,810,812],{"class":99,"line":140},[97,742,730],{"class":721},[97,744,745],{"class":103}," path ",[97,747,162],{"class":721},[97,749,750],{"class":103}," hash.",[97,752,753],{"class":158},"replace",[97,755,756],{"class":103},"(",[97,758,271],{"class":165},[97,760,761],{"class":721},"^",[97,763,16],{"class":764},"sQeJH",[97,766,271],{"class":165},[97,768,261],{"class":103},[97,770,771],{"class":165},"\"\"",[97,773,774],{"class":103},").",[97,776,777],{"class":158},"split",[97,779,756],{"class":103},[97,781,782],{"class":165},"\"?\"",[97,784,785],{"class":103},")[",[97,787,789],{"class":788},"suiK_","0",[97,791,792],{"class":103},"].",[97,794,753],{"class":158},[97,796,756],{"class":103},[97,798,271],{"class":165},[97,800,802],{"class":801},"sAxt1","\\\u002F",[97,804,805],{"class":721},"+$",[97,807,271],{"class":165},[97,809,261],{"class":103},[97,811,771],{"class":165},[97,813,814],{"class":103},");\n",[97,816,817,819,822,824,827,829,831,833,835,837,840,843,846,848,851,854,857,859,861,864,866,868,870,873],{"class":99,"line":150},[97,818,730],{"class":721},[97,820,821],{"class":103}," isAdminHash ",[97,823,162],{"class":721},[97,825,826],{"class":165}," \u002F",[97,828,761],{"class":721},[97,830,16],{"class":764},[97,832,802],{"class":801},[97,834,271],{"class":165},[97,836,280],{"class":103},[97,838,839],{"class":158},"test",[97,841,842],{"class":103},"(hash) ",[97,844,845],{"class":721},"&&",[97,847,745],{"class":103},[97,849,850],{"class":721},"!==",[97,852,853],{"class":165}," \"\"",[97,855,856],{"class":721}," &&",[97,858,745],{"class":103},[97,860,850],{"class":721},[97,862,863],{"class":165}," \"\u002Flanding\"",[97,865,856],{"class":721},[97,867,745],{"class":103},[97,869,850],{"class":721},[97,871,872],{"class":165}," \"\u002Flanding\u002Fhome\"",[97,874,875],{"class":103},";\n",[97,877,878],{"class":99,"line":182},[97,879,880],{"class":172},"    \u002F\u002F An existing short link, \u002Fm, only gets here because unknown paths fall back to index.html. Hand it back to admin\n",[97,882,883,885,888,890,892,894,897,900,902,904,906],{"class":99,"line":213},[97,884,730],{"class":721},[97,886,887],{"class":103}," isShortEntry ",[97,889,162],{"class":721},[97,891,826],{"class":165},[97,893,802],{"class":801},[97,895,896],{"class":764},"m",[97,898,899],{"class":721},"$",[97,901,271],{"class":165},[97,903,280],{"class":103},[97,905,839],{"class":158},[97,907,908],{"class":103},"(location.pathname);\n",[97,910,911,913,916,918,921,924,926,928],{"class":99,"line":581},[97,912,730],{"class":721},[97,914,915],{"class":103}," landing ",[97,917,162],{"class":721},[97,919,920],{"class":721}," !",[97,922,923],{"class":103},"isAdminHash ",[97,925,845],{"class":721},[97,927,920],{"class":721},[97,929,930],{"class":103},"isShortEntry;\n",[97,932,933,936,938],{"class":99,"line":587},[97,934,935],{"class":103},"    window.__LANDING__ ",[97,937,162],{"class":721},[97,939,940],{"class":103}," landing;\n",[97,942,944,947,950,952,955,958,961,964],{"class":99,"line":943},10,[97,945,946],{"class":103},"    document.documentElement.className ",[97,948,949],{"class":721},"+=",[97,951,915],{"class":103},[97,953,954],{"class":721},"?",[97,956,957],{"class":165}," \" boot-landing\"",[97,959,960],{"class":721}," :",[97,962,963],{"class":165}," \" boot-admin\"",[97,965,875],{"class":103},[97,967,969,972],{"class":99,"line":968},11,[97,970,971],{"class":721},"    if",[97,973,974],{"class":103}," (landing) {\n",[97,976,978],{"class":99,"line":977},12,[97,979,980],{"class":172},"      \u002F\u002F Tidy old URLs like \u002F#\u002Flanding\u002Fhome and \u002F#\u002F into a clean one, without a reload\n",[97,982,984,987,990,992,994,996,998,1000,1002,1004,1007,1010,1013,1015,1018,1021],{"class":99,"line":983},13,[97,985,986],{"class":721},"      if",[97,988,989],{"class":103}," (",[97,991,271],{"class":165},[97,993,761],{"class":721},[97,995,16],{"class":764},[97,997,802],{"class":801},[97,999,271],{"class":165},[97,1001,280],{"class":103},[97,1003,839],{"class":158},[97,1005,1006],{"class":103},"(hash)) history.",[97,1008,1009],{"class":158},"replaceState",[97,1011,1012],{"class":103},"(history.state, ",[97,1014,771],{"class":165},[97,1016,1017],{"class":103},", location.pathname ",[97,1019,1020],{"class":721},"+",[97,1022,1023],{"class":103}," location.search);\n",[97,1025,1027,1030,1033],{"class":99,"line":1026},14,[97,1028,1029],{"class":103},"    } ",[97,1031,1032],{"class":721},"else",[97,1034,1035],{"class":103}," {\n",[97,1037,1039,1042,1044,1047],{"class":99,"line":1038},15,[97,1040,1041],{"class":103},"      document.title ",[97,1043,162],{"class":721},[97,1045,1046],{"class":165}," \"Admin\"",[97,1048,875],{"class":103},[97,1050,1052],{"class":99,"line":1051},16,[97,1053,1054],{"class":103},"    }\n",[97,1056,1058],{"class":99,"line":1057},17,[97,1059,1060],{"class":103},"  })();\n",[97,1062,1064,1066,1068],{"class":99,"line":1063},18,[97,1065,133],{"class":103},[97,1067,187],{"class":107},[97,1069,111],{"class":103},[10,1071,1072],{},"Four things worth pointing out:",[39,1074,1075,1088,1101,1113],{},[42,1076,1077,1083,1084,1087],{},[22,1078,1079,1080,1082],{},"Only a hash that starts with ",[14,1081,616],{}," counts as a route."," A plain anchor like ",[14,1085,1086],{},"#section",", or a fragment some ad platform tacked on, still means the home page.",[42,1089,1090,1093,1094,1096,1097,1100],{},[22,1091,1092],{},"Track down everything that quietly relies on the fallback."," The static host serves ",[14,1095,70],{}," for unknown paths, and we had a short link, ",[14,1098,1099],{},"\u002Fm",", that depended on exactly that: it would land in the admin app, and the router would rewrite it to a mobile page. After the split it would have been mistaken for the home page, so the script excludes it by path. Hidden dependencies like this aren't in any route table. The only way to find them is to go digging through code and config.",[42,1102,1103,1109,1110,1112],{},[22,1104,1105,1106,1108],{},"Old URLs get cleaned up with ",[14,1107,1009],{},", not a redirect."," Any ",[14,1111,260],{}," link already floating around opens with a clean address bar, costs no extra request, and keeps its query string.",[42,1114,1115,1121],{},[22,1116,1117,1120],{},[14,1118,1119],{},"\u003Ctitle>"," defaults to the home page's title",", since that's what crawlers read, and the script swaps it back for admin. Do it the other way around and any crawler that skips JS sees the admin title.",[10,1123,1124],{},"The real entry file does nothing but pick one:",[88,1126,1130],{"className":1127,"code":1128,"language":1129,"meta":93,"style":93},"language-ts shiki shiki-themes github-light github-dark github-dark","\u002F\u002F src\u002Fboot.ts\nif (window.__LANDING__) {\n  import(\".\u002Flanding\u002Fmain\");\n} else {\n  import(\".\u002Fmain\"); \u002F\u002F the original admin entry, not one line changed\n}\n","ts",[14,1131,1132,1137,1145,1157,1166,1181],{"__ignoreMap":93},[97,1133,1134],{"class":99,"line":100},[97,1135,1136],{"class":172},"\u002F\u002F src\u002Fboot.ts\n",[97,1138,1139,1142],{"class":99,"line":114},[97,1140,1141],{"class":721},"if",[97,1143,1144],{"class":103}," (window.__LANDING__) {\n",[97,1146,1147,1150,1152,1155],{"class":99,"line":130},[97,1148,1149],{"class":721},"  import",[97,1151,756],{"class":103},[97,1153,1154],{"class":165},"\".\u002Flanding\u002Fmain\"",[97,1156,814],{"class":103},[97,1158,1159,1162,1164],{"class":99,"line":140},[97,1160,1161],{"class":103},"} ",[97,1163,1032],{"class":721},[97,1165,1035],{"class":103},[97,1167,1168,1170,1172,1175,1178],{"class":99,"line":150},[97,1169,1149],{"class":721},[97,1171,756],{"class":103},[97,1173,1174],{"class":165},"\".\u002Fmain\"",[97,1176,1177],{"class":103},"); ",[97,1179,1180],{"class":172},"\u002F\u002F the original admin entry, not one line changed\n",[97,1182,1183],{"class":99,"line":182},[97,1184,1185],{"class":103},"}\n",[10,1187,1188,1189,1192],{},"Because both are dynamic ",[14,1190,1191],{},"import()"," calls, the bundler splits them into two sets of chunks with nothing shared that shouldn't be. Home page visitors no longer pull down the admin bundle. Before this, the home page was a route inside the admin app, so every visitor downloaded the entire UI component library along with it.",[690,1194,1196],{"id":1195},"_42-the-build-plugin","4.2 The build plugin",[10,1198,1199,1200,1203,1204,280],{},"I hooked prerendering onto the end of the build as a Vite plugin instead of adding another command to ",[14,1201,1202],{},"package.json",". The reason is mundane: I wasn't sure which build command our release pipeline actually calls, and a plugin means ",[22,1205,1206,1207,1210],{},"it runs any time ",[14,1208,1209],{},"vite build"," runs",[88,1212,1214],{"className":1127,"code":1213,"language":1129,"meta":93,"style":93},"\u002F\u002F build\u002FprerenderLanding.ts (skeleton)\nexport const prerenderLanding = (): Plugin => {\n  let config: ResolvedConfig;\n  let written = false;\n\n  return {\n    name: \"prerender-landing\",\n    apply: \"build\",\n    config: (_, { isSsrBuild }) => (isSsrBuild ? undefined : { build: { manifest: true } }),\n    configResolved: resolved => void (config = resolved),\n    writeBundle: () => void (written = true),\n\n    async closeBundle() {\n      \u002F\u002F closeBundle also fires when the build fails, and the nested SSR build loads this plugin too\n      if (config.build.ssr || !written) return;\n\n      \u002F\u002F 1. Run a second, SSR build with the same config, bundling only the home page's server entry\n      await build({\n        configFile: config.configFile,\n        mode: config.mode,\n        build: { ssr: \"src\u002Flanding\u002Fentry-server.ts\", outDir: ssrOutDir, copyPublicDir: false }\n      });\n\n      \u002F\u002F 2. Render and write back into dist\u002Findex.html\n      const { render } = await import(pathToFileURL(ssrEntry).href);\n      const landingHtml = patchLandingHtml(await render());\n      html = html.replace(CONTAINER_RE, () => `\u003Cdiv id=\"landing-root\" data-prerendered>${landingHtml}\u003C\u002Fdiv>`);\n      fs.writeFileSync(htmlPath, html);\n    }\n  };\n};\n",[14,1215,1216,1221,1248,1263,1277,1283,1290,1301,1311,1354,1378,1401,1405,1416,1421,1441,1445,1450,1461,1467,1473,1491,1497,1502,1508,1539,1563,1597,1609,1614,1620],{"__ignoreMap":93},[97,1217,1218],{"class":99,"line":100},[97,1219,1220],{"class":172},"\u002F\u002F build\u002FprerenderLanding.ts (skeleton)\n",[97,1222,1223,1226,1229,1232,1235,1238,1240,1243,1246],{"class":99,"line":114},[97,1224,1225],{"class":721},"export",[97,1227,1228],{"class":721}," const",[97,1230,1231],{"class":158}," prerenderLanding",[97,1233,1234],{"class":721}," =",[97,1236,1237],{"class":103}," ()",[97,1239,633],{"class":721},[97,1241,1242],{"class":158}," Plugin",[97,1244,1245],{"class":721}," =>",[97,1247,1035],{"class":103},[97,1249,1250,1253,1256,1258,1261],{"class":99,"line":130},[97,1251,1252],{"class":721},"  let",[97,1254,1255],{"class":103}," config",[97,1257,633],{"class":721},[97,1259,1260],{"class":158}," ResolvedConfig",[97,1262,875],{"class":103},[97,1264,1265,1267,1270,1272,1275],{"class":99,"line":140},[97,1266,1252],{"class":721},[97,1268,1269],{"class":103}," written ",[97,1271,162],{"class":721},[97,1273,1274],{"class":788}," false",[97,1276,875],{"class":103},[97,1278,1279],{"class":99,"line":150},[97,1280,1282],{"emptyLinePlaceholder":1281},true,"\n",[97,1284,1285,1288],{"class":99,"line":182},[97,1286,1287],{"class":721},"  return",[97,1289,1035],{"class":103},[97,1291,1292,1295,1298],{"class":99,"line":213},[97,1293,1294],{"class":103},"    name: ",[97,1296,1297],{"class":165},"\"prerender-landing\"",[97,1299,1300],{"class":103},",\n",[97,1302,1303,1306,1309],{"class":99,"line":581},[97,1304,1305],{"class":103},"    apply: ",[97,1307,1308],{"class":165},"\"build\"",[97,1310,1300],{"class":103},[97,1312,1313,1316,1319,1323,1326,1329,1332,1335,1338,1340,1343,1345,1348,1351],{"class":99,"line":587},[97,1314,1315],{"class":158},"    config",[97,1317,1318],{"class":103},": (",[97,1320,1322],{"class":1321},"sQHwn","_",[97,1324,1325],{"class":103},", { ",[97,1327,1328],{"class":1321},"isSsrBuild",[97,1330,1331],{"class":103}," }) ",[97,1333,1334],{"class":721},"=>",[97,1336,1337],{"class":103}," (isSsrBuild ",[97,1339,954],{"class":721},[97,1341,1342],{"class":788}," undefined",[97,1344,960],{"class":721},[97,1346,1347],{"class":103}," { build: { manifest: ",[97,1349,1350],{"class":788},"true",[97,1352,1353],{"class":103}," } }),\n",[97,1355,1356,1359,1362,1365,1367,1370,1373,1375],{"class":99,"line":943},[97,1357,1358],{"class":158},"    configResolved",[97,1360,1361],{"class":103},": ",[97,1363,1364],{"class":1321},"resolved",[97,1366,1245],{"class":721},[97,1368,1369],{"class":721}," void",[97,1371,1372],{"class":103}," (config ",[97,1374,162],{"class":721},[97,1376,1377],{"class":103}," resolved),\n",[97,1379,1380,1383,1386,1388,1390,1393,1395,1398],{"class":99,"line":968},[97,1381,1382],{"class":158},"    writeBundle",[97,1384,1385],{"class":103},": () ",[97,1387,1334],{"class":721},[97,1389,1369],{"class":721},[97,1391,1392],{"class":103}," (written ",[97,1394,162],{"class":721},[97,1396,1397],{"class":788}," true",[97,1399,1400],{"class":103},"),\n",[97,1402,1403],{"class":99,"line":977},[97,1404,1282],{"emptyLinePlaceholder":1281},[97,1406,1407,1410,1413],{"class":99,"line":983},[97,1408,1409],{"class":721},"    async",[97,1411,1412],{"class":158}," closeBundle",[97,1414,1415],{"class":103},"() {\n",[97,1417,1418],{"class":99,"line":1026},[97,1419,1420],{"class":172},"      \u002F\u002F closeBundle also fires when the build fails, and the nested SSR build loads this plugin too\n",[97,1422,1423,1425,1428,1431,1433,1436,1439],{"class":99,"line":1038},[97,1424,986],{"class":721},[97,1426,1427],{"class":103}," (config.build.ssr ",[97,1429,1430],{"class":721},"||",[97,1432,920],{"class":721},[97,1434,1435],{"class":103},"written) ",[97,1437,1438],{"class":721},"return",[97,1440,875],{"class":103},[97,1442,1443],{"class":99,"line":1051},[97,1444,1282],{"emptyLinePlaceholder":1281},[97,1446,1447],{"class":99,"line":1057},[97,1448,1449],{"class":172},"      \u002F\u002F 1. Run a second, SSR build with the same config, bundling only the home page's server entry\n",[97,1451,1452,1455,1458],{"class":99,"line":1063},[97,1453,1454],{"class":721},"      await",[97,1456,1457],{"class":158}," build",[97,1459,1460],{"class":103},"({\n",[97,1462,1464],{"class":99,"line":1463},19,[97,1465,1466],{"class":103},"        configFile: config.configFile,\n",[97,1468,1470],{"class":99,"line":1469},20,[97,1471,1472],{"class":103},"        mode: config.mode,\n",[97,1474,1476,1479,1482,1485,1488],{"class":99,"line":1475},21,[97,1477,1478],{"class":103},"        build: { ssr: ",[97,1480,1481],{"class":165},"\"src\u002Flanding\u002Fentry-server.ts\"",[97,1483,1484],{"class":103},", outDir: ssrOutDir, copyPublicDir: ",[97,1486,1487],{"class":788},"false",[97,1489,1490],{"class":103}," }\n",[97,1492,1494],{"class":99,"line":1493},22,[97,1495,1496],{"class":103},"      });\n",[97,1498,1500],{"class":99,"line":1499},23,[97,1501,1282],{"emptyLinePlaceholder":1281},[97,1503,1505],{"class":99,"line":1504},24,[97,1506,1507],{"class":172},"      \u002F\u002F 2. Render and write back into dist\u002Findex.html\n",[97,1509,1511,1514,1517,1520,1523,1525,1528,1531,1533,1536],{"class":99,"line":1510},25,[97,1512,1513],{"class":721},"      const",[97,1515,1516],{"class":103}," { ",[97,1518,1519],{"class":788},"render",[97,1521,1522],{"class":103}," } ",[97,1524,162],{"class":721},[97,1526,1527],{"class":721}," await",[97,1529,1530],{"class":158}," import",[97,1532,756],{"class":103},[97,1534,1535],{"class":158},"pathToFileURL",[97,1537,1538],{"class":103},"(ssrEntry).href);\n",[97,1540,1542,1544,1547,1549,1552,1554,1557,1560],{"class":99,"line":1541},26,[97,1543,1513],{"class":721},[97,1545,1546],{"class":788}," landingHtml",[97,1548,1234],{"class":721},[97,1550,1551],{"class":158}," patchLandingHtml",[97,1553,756],{"class":103},[97,1555,1556],{"class":721},"await",[97,1558,1559],{"class":158}," render",[97,1561,1562],{"class":103},"());\n",[97,1564,1566,1569,1571,1574,1576,1578,1581,1584,1586,1589,1592,1595],{"class":99,"line":1565},27,[97,1567,1568],{"class":103},"      html ",[97,1570,162],{"class":721},[97,1572,1573],{"class":103}," html.",[97,1575,753],{"class":158},[97,1577,756],{"class":103},[97,1579,1580],{"class":788},"CONTAINER_RE",[97,1582,1583],{"class":103},", () ",[97,1585,1334],{"class":721},[97,1587,1588],{"class":165}," `\u003Cdiv id=\"landing-root\" data-prerendered>${",[97,1590,1591],{"class":103},"landingHtml",[97,1593,1594],{"class":165},"}\u003C\u002Fdiv>`",[97,1596,814],{"class":103},[97,1598,1600,1603,1606],{"class":99,"line":1599},28,[97,1601,1602],{"class":103},"      fs.",[97,1604,1605],{"class":158},"writeFileSync",[97,1607,1608],{"class":103},"(htmlPath, html);\n",[97,1610,1612],{"class":99,"line":1611},29,[97,1613,1054],{"class":103},[97,1615,1617],{"class":99,"line":1616},30,[97,1618,1619],{"class":103},"  };\n",[97,1621,1623],{"class":99,"line":1622},31,[97,1624,1625],{"class":103},"};\n",[10,1627,1628],{},"The server entry is three lines that matter:",[88,1630,1632],{"className":1127,"code":1631,"language":1129,"meta":93,"style":93},"\u002F\u002F src\u002Flanding\u002Fentry-server.ts\nimport { createSSRApp } from \"vue\";\nimport { renderToString } from \"vue\u002Fserver-renderer\";\nimport Home from \"@\u002Fviews\u002Flanding\u002Fhome.vue\";\n\nexport const render = () => renderToString(createSSRApp(Home));\n",[14,1633,1634,1639,1655,1669,1683,1687],{"__ignoreMap":93},[97,1635,1636],{"class":99,"line":100},[97,1637,1638],{"class":172},"\u002F\u002F src\u002Flanding\u002Fentry-server.ts\n",[97,1640,1641,1644,1647,1650,1653],{"class":99,"line":114},[97,1642,1643],{"class":721},"import",[97,1645,1646],{"class":103}," { createSSRApp } ",[97,1648,1649],{"class":721},"from",[97,1651,1652],{"class":165}," \"vue\"",[97,1654,875],{"class":103},[97,1656,1657,1659,1662,1664,1667],{"class":99,"line":130},[97,1658,1643],{"class":721},[97,1660,1661],{"class":103}," { renderToString } ",[97,1663,1649],{"class":721},[97,1665,1666],{"class":165}," \"vue\u002Fserver-renderer\"",[97,1668,875],{"class":103},[97,1670,1671,1673,1676,1678,1681],{"class":99,"line":140},[97,1672,1643],{"class":721},[97,1674,1675],{"class":103}," Home ",[97,1677,1649],{"class":721},[97,1679,1680],{"class":165}," \"@\u002Fviews\u002Flanding\u002Fhome.vue\"",[97,1682,875],{"class":103},[97,1684,1685],{"class":99,"line":150},[97,1686,1282],{"emptyLinePlaceholder":1281},[97,1688,1689,1691,1693,1695,1697,1700,1702,1705,1707,1710],{"class":99,"line":182},[97,1690,1225],{"class":721},[97,1692,1228],{"class":721},[97,1694,1559],{"class":158},[97,1696,1234],{"class":721},[97,1698,1699],{"class":103}," () ",[97,1701,1334],{"class":721},[97,1703,1704],{"class":158}," renderToString",[97,1706,756],{"class":103},[97,1708,1709],{"class":158},"createSSRApp",[97,1711,1712],{"class":103},"(Home));\n",[10,1714,1715],{},"A few choices here deserve an explanation:",[39,1717,1718,1727,1744,1767],{},[42,1719,1720,1726],{},[22,1721,1722,1723,280],{},"The SSR build reuses the same ",[14,1724,1725],{},"vite.config"," Aliases, plugins, and asset naming are identical, so the image URLs coming out of the server render, content hashes included, line up with the client build's files. There's no mapping step.",[42,1728,1729,1736,1737,1740,1741,1743],{},[22,1730,1731,1732,1735],{},"The ",[14,1733,1734],{},"written"," flag."," Rollup calls ",[14,1738,1739],{},"closeBundle"," even when the build fails. Without this guard, the plugin would try to patch an ",[14,1742,70],{}," left over from an earlier build, then throw an error that has nothing to do with what actually went wrong and bury the real one.",[42,1745,1746,1752,1753,1756,1757,234,1760,1763,1764,1766],{},[22,1747,1748,1749,1751],{},"Pass a function to ",[14,1750,753],{},", not a string."," When the second argument to ",[14,1754,1755],{},"String.prototype.replace"," is a string, sequences like ",[14,1758,1759],{},"$&",[14,1761,1762],{},"$1"," in it are treated as placeholders. Marketing copy with a ",[14,1765,899],{}," in it is hardly unusual (think prices), and the function form sidesteps the whole issue.",[42,1768,1769,1772],{},[22,1770,1771],{},"A failed prerender fails the build."," It throws. I'd much rather ship nothing than quietly publish a home page with no body text. Nothing errors when that happens, and you only find out when traffic falls off.",[690,1774,1776],{"id":1775},"_43-the-browser-entry","4.3 The browser entry",[88,1778,1780],{"className":1127,"code":1779,"language":1129,"meta":93,"style":93},"\u002F\u002F src\u002Flanding\u002Fmain.ts\nconst container = document.getElementById(\"landing-root\")!;\n\n\u002F\u002F By the time this module runs, its styles have loaded (the bundler waits for CSS dependencies)\ndocument.getElementById(\"app\")?.remove(); \u002F\u002F drop the loading spinner\ndocument.documentElement.classList.add(\"landing-ready\"); \u002F\u002F reveal the home page container\n\nconst prerendered = container.hasAttribute(\"data-prerendered\");\nconst app = prerendered ? createSSRApp(Home) : createApp(Home);\napp.mount(container);\n\n\u002F\u002F Going to admin from the home page only changes the hash. There is no router here,\n\u002F\u002F so reload once and let the boot script load admin\nwindow.addEventListener(\"hashchange\", () => {\n  if (isAdminHash(location.hash)) location.reload();\n});\n",[14,1781,1782,1787,1816,1820,1825,1848,1866,1870,1892,1920,1931,1935,1940,1945,1964,1983],{"__ignoreMap":93},[97,1783,1784],{"class":99,"line":100},[97,1785,1786],{"class":172},"\u002F\u002F src\u002Flanding\u002Fmain.ts\n",[97,1788,1789,1792,1795,1797,1800,1803,1805,1808,1811,1814],{"class":99,"line":114},[97,1790,1791],{"class":721},"const",[97,1793,1794],{"class":788}," container",[97,1796,1234],{"class":721},[97,1798,1799],{"class":103}," document.",[97,1801,1802],{"class":158},"getElementById",[97,1804,756],{"class":103},[97,1806,1807],{"class":165},"\"landing-root\"",[97,1809,1810],{"class":103},")",[97,1812,1813],{"class":721},"!",[97,1815,875],{"class":103},[97,1817,1818],{"class":99,"line":130},[97,1819,1282],{"emptyLinePlaceholder":1281},[97,1821,1822],{"class":99,"line":140},[97,1823,1824],{"class":172},"\u002F\u002F By the time this module runs, its styles have loaded (the bundler waits for CSS dependencies)\n",[97,1826,1827,1830,1832,1834,1836,1839,1842,1845],{"class":99,"line":150},[97,1828,1829],{"class":103},"document.",[97,1831,1802],{"class":158},[97,1833,756],{"class":103},[97,1835,166],{"class":165},[97,1837,1838],{"class":103},")?.",[97,1840,1841],{"class":158},"remove",[97,1843,1844],{"class":103},"(); ",[97,1846,1847],{"class":172},"\u002F\u002F drop the loading spinner\n",[97,1849,1850,1853,1856,1858,1861,1863],{"class":99,"line":182},[97,1851,1852],{"class":103},"document.documentElement.classList.",[97,1854,1855],{"class":158},"add",[97,1857,756],{"class":103},[97,1859,1860],{"class":165},"\"landing-ready\"",[97,1862,1177],{"class":103},[97,1864,1865],{"class":172},"\u002F\u002F reveal the home page container\n",[97,1867,1868],{"class":99,"line":213},[97,1869,1282],{"emptyLinePlaceholder":1281},[97,1871,1872,1874,1877,1879,1882,1885,1887,1890],{"class":99,"line":581},[97,1873,1791],{"class":721},[97,1875,1876],{"class":788}," prerendered",[97,1878,1234],{"class":721},[97,1880,1881],{"class":103}," container.",[97,1883,1884],{"class":158},"hasAttribute",[97,1886,756],{"class":103},[97,1888,1889],{"class":165},"\"data-prerendered\"",[97,1891,814],{"class":103},[97,1893,1894,1896,1899,1901,1904,1906,1909,1912,1914,1917],{"class":99,"line":587},[97,1895,1791],{"class":721},[97,1897,1898],{"class":788}," app",[97,1900,1234],{"class":721},[97,1902,1903],{"class":103}," prerendered ",[97,1905,954],{"class":721},[97,1907,1908],{"class":158}," createSSRApp",[97,1910,1911],{"class":103},"(Home) ",[97,1913,633],{"class":721},[97,1915,1916],{"class":158}," createApp",[97,1918,1919],{"class":103},"(Home);\n",[97,1921,1922,1925,1928],{"class":99,"line":943},[97,1923,1924],{"class":103},"app.",[97,1926,1927],{"class":158},"mount",[97,1929,1930],{"class":103},"(container);\n",[97,1932,1933],{"class":99,"line":968},[97,1934,1282],{"emptyLinePlaceholder":1281},[97,1936,1937],{"class":99,"line":977},[97,1938,1939],{"class":172},"\u002F\u002F Going to admin from the home page only changes the hash. There is no router here,\n",[97,1941,1942],{"class":99,"line":983},[97,1943,1944],{"class":172},"\u002F\u002F so reload once and let the boot script load admin\n",[97,1946,1947,1950,1953,1955,1958,1960,1962],{"class":99,"line":1026},[97,1948,1949],{"class":103},"window.",[97,1951,1952],{"class":158},"addEventListener",[97,1954,756],{"class":103},[97,1956,1957],{"class":165},"\"hashchange\"",[97,1959,1583],{"class":103},[97,1961,1334],{"class":721},[97,1963,1035],{"class":103},[97,1965,1966,1969,1971,1974,1977,1980],{"class":99,"line":1038},[97,1967,1968],{"class":721},"  if",[97,1970,989],{"class":103},[97,1972,1973],{"class":158},"isAdminHash",[97,1975,1976],{"class":103},"(location.hash)) location.",[97,1978,1979],{"class":158},"reload",[97,1981,1982],{"class":103},"();\n",[97,1984,1985],{"class":99,"line":1051},[97,1986,1987],{"class":103},"});\n",[10,1989,1990,1993,1994,234,1996,1999,2000,244,2003,2006],{},[14,1991,1992],{},"data-prerendered"," is a marker the build plugin leaves behind. Production builds have it, so the entry calls ",[14,1995,1709],{},[22,1997,1998],{},"hydrates",", which means wiring events and reactivity onto the DOM that's already there instead of rebuilding it. In local dev the container is empty, so it falls back to a plain ",[14,2001,2002],{},"createApp",[22,2004,2005],{},"One entry file covers both cases",", and the dev workflow doesn't change.",[10,2008,2009,2010,2013,2014,2017,2018,2021,2022,2025],{},"Buttons on the home page that used to call ",[14,2011,2012],{},"router.push(\"\u002Foverview\")"," now just set ",[14,2015,2016],{},"location.hash = \"#\u002Foverview\"",". What I like about this is that it ",[22,2019,2020],{},"works whether or not there's a router",". On the standalone home page it fires the ",[14,2023,2024],{},"hashchange"," listener above. The header and footer are also shared with a legal page that still lives in the admin app, and over there the hash router picks up the very same change.",[73,2027,2029],{"id":2028},"_5-four-things-that-only-bite-once-you-ship","5. Four Things That Only Bite Once You Ship",[690,2031,2033],{"id":2032},"pitfall-1-the-content-shows-up-before-its-styles","Pitfall 1: the content shows up before its styles",[10,2035,2036],{},"Once the page is prerendered, the home page's markup is in the DOM the instant the HTML arrives. Its CSS, though, is a dependency of the JS entry and loads a beat later. What you get is a flash of raw, completely unstyled HTML.",[10,2038,2039,2040,2042],{},"The fix is to collapse the container with an inline style in ",[14,2041,699],{},", then let it go once the entry runs:",[88,2044,2048],{"className":2045,"code":2046,"language":2047,"meta":93,"style":93},"language-css shiki shiki-themes github-light github-dark github-dark","html.boot-landing:not(.landing-ready) #landing-root {\n  height: 0;\n  overflow: hidden;\n  visibility: hidden;\n}\n","css",[14,2049,2050,2070,2081,2093,2104],{"__ignoreMap":93},[97,2051,2052,2054,2057,2059,2062,2065,2068],{"class":99,"line":100},[97,2053,92],{"class":107},[97,2055,2056],{"class":158},".boot-landing:not",[97,2058,756],{"class":103},[97,2060,2061],{"class":158},".landing-ready",[97,2063,2064],{"class":103},") ",[97,2066,2067],{"class":158},"#landing-root",[97,2069,1035],{"class":103},[97,2071,2072,2075,2077,2079],{"class":99,"line":114},[97,2073,2074],{"class":788},"  height",[97,2076,1361],{"class":103},[97,2078,789],{"class":788},[97,2080,875],{"class":103},[97,2082,2083,2086,2088,2091],{"class":99,"line":130},[97,2084,2085],{"class":788},"  overflow",[97,2087,1361],{"class":103},[97,2089,2090],{"class":788},"hidden",[97,2092,875],{"class":103},[97,2094,2095,2098,2100,2102],{"class":99,"line":140},[97,2096,2097],{"class":788},"  visibility",[97,2099,1361],{"class":103},[97,2101,2090],{"class":788},[97,2103,875],{"class":103},[97,2105,2106],{"class":99,"line":150},[97,2107,1185],{"class":103},[10,2109,2110,2111,2114],{},"Crawlers don't care. The ones that skip JS parse the text and ignore visibility, and the ones that run JS see the final state. But it does mean ",[22,2112,2113],{},"prerendering didn't get the page in front of users any faster",". That's a real limitation, and I come back to it in section 8.",[690,2116,2118],{"id":2117},"pitfall-2-the-ssr-builds-asset-urls-break-under-a-subdirectory-deploy","Pitfall 2: the SSR build's asset URLs break under a subdirectory deploy",[10,2120,2121,2122,2125,2126,2128],{},"My ",[14,2123,2124],{},"base"," is the relative ",[14,2127,390],{},", so the same build works at a domain root or in any subdirectory. The client build resolves assets relative to the current file. The SSR build doesn't. Here's the branch in the Vite 5 source:",[88,2130,2134],{"className":2131,"code":2132,"language":2133,"meta":93,"style":93},"language-js shiki shiki-themes github-light github-dark github-dark","if (relative && !config.build.ssr) {\n  return toRelative(filename, hostId);\n}\nreturn joinUrlSegments(config.base, filename);\n","js",[14,2135,2136,2150,2160,2164],{"__ignoreMap":93},[97,2137,2138,2140,2143,2145,2147],{"class":99,"line":100},[97,2139,1141],{"class":721},[97,2141,2142],{"class":103}," (relative ",[97,2144,845],{"class":721},[97,2146,920],{"class":721},[97,2148,2149],{"class":103},"config.build.ssr) {\n",[97,2151,2152,2154,2157],{"class":99,"line":114},[97,2153,1287],{"class":721},[97,2155,2156],{"class":158}," toRelative",[97,2158,2159],{"class":103},"(filename, hostId);\n",[97,2161,2162],{"class":99,"line":130},[97,2163,1185],{"class":103},[97,2165,2166,2168,2171],{"class":99,"line":140},[97,2167,1438],{"class":721},[97,2169,2170],{"class":158}," joinUrlSegments",[97,2172,2173],{"class":103},"(config.base, filename);\n",[10,2175,2176,2177,261,2180,2183,2184,2187],{},"A relative base only kicks in for client builds. The SSR build emits URLs like ",[14,2178,2179],{},"\u002Fassets\u002Fpng\u002Fxxx.png",[22,2181,2182],{},"anchored at the domain root",". Production sits at the root, so it was fine. The test environment sits under ",[14,2185,2186],{},"\u002Fadmin\u002F",", and every image there came back 404.",[10,2189,2190,2191,2194,2195,2198],{},"Here's the nasty part: ",[22,2192,2193],{},"hydration won't fix it for you."," In production mode Vue doesn't patch static attributes when it hydrates, so whatever ",[14,2196,2197],{},"src"," the server wrote is what stays on the page. I had to rewrite the HTML before saving it:",[88,2200,2202],{"className":1127,"code":2201,"language":1129,"meta":93,"style":93},"html.replace(\u002F\\s(src|poster)=\"\\\u002Fassets\\\u002F\u002Fg, ' $1=\".\u002Fassets\u002F');\n",[14,2203,2204],{"__ignoreMap":93},[97,2205,2206,2209,2211,2213,2215,2218,2221,2224,2227,2229,2232,2234,2236,2239,2241,2244],{"class":99,"line":100},[97,2207,2208],{"class":103},"html.",[97,2210,753],{"class":158},[97,2212,756],{"class":103},[97,2214,271],{"class":165},[97,2216,2217],{"class":788},"\\s",[97,2219,2220],{"class":764},"(src",[97,2222,2223],{"class":721},"|",[97,2225,2226],{"class":764},"poster)=\"",[97,2228,802],{"class":801},[97,2230,2231],{"class":764},"assets",[97,2233,802],{"class":801},[97,2235,271],{"class":165},[97,2237,2238],{"class":721},"g",[97,2240,261],{"class":103},[97,2242,2243],{"class":165},"' $1=\".\u002Fassets\u002F'",[97,2245,814],{"class":103},[10,2247,2248],{},"You only see this when three things line up: a subdirectory deploy, a relative base, and prerendering. I didn't catch it until I ran a local static server that mimicked the subdirectory.",[690,2250,2252],{"id":2251},"pitfall-3-the-browser-downloads-hidden-content-anyway","Pitfall 3: the browser downloads hidden content anyway",[10,2254,2255,2256,2259,2260,2263],{},"On an admin URL, the home page HTML is dead weight. The boot script sets it to ",[14,2257,2258],{},"display: none",", and a script immediately after it removes the node altogether. That sounds airtight, but browsers have a ",[22,2261,2262],{},"preload scanner",". It races ahead of the main parser through the raw HTML and kicks off requests for images and other resources early. It has no idea those elements are about to be hidden or thrown away.",[10,2265,2266],{},"The home page has more than seventy images. Do nothing, and every admin user downloads all of them for no reason.",[10,2268,2269,2270,2273,2274,2277,2278,2281],{},"The fix is to stamp ",[14,2271,2272],{},"loading=\"lazy\""," on every image during prerendering. The preload scanner leaves lazy images alone, and a lazy image inside a hidden container never reaches the viewport, so it's never requested. Video posters don't have a lazy equivalent, so I stash ",[14,2275,2276],{},"poster"," in a ",[14,2279,2280],{},"data-"," attribute and put it back right before the home page entry mounts.",[10,2283,2284],{},"What I measured in Chrome: on an admin URL, zero requests for the home page's images or video posters. I haven't checked how the preload scanner behaves in other browsers.",[690,2286,2288],{"id":2287},"pitfall-4-removing-the-loading-spinner-took-the-page-margins-with-it","Pitfall 4: removing the loading spinner took the page margins with it",[10,2290,2291,2292,2294,2295,2298,2299,2302,2303,2306,2307,2310],{},"I did this one to myself. In the original ",[14,2293,70],{},", the few lines of CSS that zero out the margins on ",[14,2296,2297],{},"html, body"," lived in a ",[14,2300,2301],{},"\u003Cstyle>"," tag inside ",[14,2304,2305],{},"\u003Cdiv id=\"app\">",", right beside the loading spinner. When the admin app mounts it takes over ",[14,2308,2309],{},"#app",", and its own global stylesheet has the same reset, so nobody ever noticed.",[10,2312,2313,2314,2317,2318,2320,2321,2323],{},"My home page entry calls ",[14,2315,2316],{},"document.getElementById(\"app\").remove()",". The ",[14,2319,2301],{}," tag went out with it, the standalone entry doesn't load the admin's global styles, and ",[14,2322,145],{}," snapped back to the browser's default 8px margin. The whole page picked up a white border.",[10,2325,2326,2327,2329],{},"The fix is simple: move the reset into an inline style in ",[14,2328,699],{},", so it no longer hangs off a node that's going to be removed.",[88,2331,2333],{"className":90,"code":2332,"language":92,"meta":93,"style":93},"\u003Chead>\n  \u003Cstyle>\n    html,\n    body {\n      width: 100%;\n      height: 100%;\n      padding: 0;\n      margin: 0;\n    }\n  \u003C\u002Fstyle>\n\u003C\u002Fhead>\n",[14,2334,2335,2343,2352,2359,2366,2381,2394,2405,2416,2420,2429],{"__ignoreMap":93},[97,2336,2337,2339,2341],{"class":99,"line":100},[97,2338,104],{"class":103},[97,2340,108],{"class":107},[97,2342,111],{"class":103},[97,2344,2345,2347,2350],{"class":99,"line":114},[97,2346,117],{"class":103},[97,2348,2349],{"class":107},"style",[97,2351,111],{"class":103},[97,2353,2354,2357],{"class":99,"line":130},[97,2355,2356],{"class":107},"    html",[97,2358,1300],{"class":103},[97,2360,2361,2364],{"class":99,"line":140},[97,2362,2363],{"class":107},"    body",[97,2365,1035],{"class":103},[97,2367,2368,2371,2373,2376,2379],{"class":99,"line":150},[97,2369,2370],{"class":788},"      width",[97,2372,1361],{"class":103},[97,2374,2375],{"class":788},"100",[97,2377,2378],{"class":721},"%",[97,2380,875],{"class":103},[97,2382,2383,2386,2388,2390,2392],{"class":99,"line":182},[97,2384,2385],{"class":788},"      height",[97,2387,1361],{"class":103},[97,2389,2375],{"class":788},[97,2391,2378],{"class":721},[97,2393,875],{"class":103},[97,2395,2396,2399,2401,2403],{"class":99,"line":213},[97,2397,2398],{"class":788},"      padding",[97,2400,1361],{"class":103},[97,2402,789],{"class":788},[97,2404,875],{"class":103},[97,2406,2407,2410,2412,2414],{"class":99,"line":581},[97,2408,2409],{"class":788},"      margin",[97,2411,1361],{"class":103},[97,2413,789],{"class":788},[97,2415,875],{"class":103},[97,2417,2418],{"class":99,"line":587},[97,2419,1054],{"class":103},[97,2421,2422,2425,2427],{"class":99,"line":943},[97,2423,2424],{"class":103},"  \u003C\u002F",[97,2426,2349],{"class":107},[97,2428,111],{"class":103},[97,2430,2431,2433,2435],{"class":99,"line":968},[97,2432,133],{"class":103},[97,2434,108],{"class":107},[97,2436,111],{"class":103},[10,2438,2439,2440,2442],{},"I left the original copy inside ",[14,2441,2309],{}," alone. The admin entry still works the way it always has, and deduplicating two CSS rules isn't a good enough reason to touch a path that's been running fine for a long time.",[10,2444,2445,2446,2452],{},"The real lesson here is bigger than 8px: ",[22,2447,2448,2449,2451],{},"when a node is removed, any ",[14,2450,2301],{}," inside it stops applying",", and nobody keeps track of which node a global style happens to live in. If you're about to delete or replace a container that was already on the page, check first whether it's carrying styles or scripts along with it.",[10,2454,2455,2456,2459],{},"Type checking passed. Lint passed. The build passed. Every piece of runtime state my script read was correct. ",[22,2457,2458],{},"It took a screenshot to catch it."," More on that in the takeaways.",[73,2461,2463],{"id":2462},"_6-getting-preloading-back-after-the-entries-went-dynamic","6. Getting Preloading Back After the Entries Went Dynamic",[10,2465,2466,2467,2470,2471,2474,2475,280],{},"Before any of this, the ",[14,2468,2469],{},"\u003Cscript type=\"module\">"," in the HTML pointed straight at the admin entry, and the bundler emitted ",[14,2472,2473],{},"\u003Clink rel=\"modulepreload\">"," tags for its static dependencies. The browser could start downloading them in parallel as soon as it parsed ",[14,2476,699],{},[10,2478,2479,2480,2483,2484,2486,2487,2489,2490,2493],{},"Now the HTML points at ",[14,2481,2482],{},"boot.ts",", which is a handful of lines, and both real entries are dynamic ",[14,2485,1191],{}," calls. Bundlers don't emit preload tags in the HTML for dynamic entries. So the browser has to download and run ",[14,2488,2482],{}," before it even knows what to fetch next. That's ",[22,2491,2492],{},"one extra round trip",", and a performance regression for admin users that I wasn't going to accept.",[10,2495,2496,2497,633],{},"To fix it, the build plugin reads Vite's manifest, which records the output file for each entry and the files it statically depends on. From that it works out what each of the two entries needs on first load, and injects an inline script just before ",[14,2498,2499],{},"\u003C\u002Fhead>",[88,2501,2503],{"className":2131,"code":2502,"language":2133,"meta":93,"style":93},"var files = window.__LANDING__ ? manifest.landing : manifest.admin;\nfiles.js.forEach(function (f) { add(\"modulepreload\", f); });\nfiles.css.forEach(function (f) { add(\"preload\", f, \"style\"); });\n",[14,2504,2505,2528,2558],{"__ignoreMap":93},[97,2506,2507,2510,2513,2515,2518,2520,2523,2525],{"class":99,"line":100},[97,2508,2509],{"class":721},"var",[97,2511,2512],{"class":103}," files ",[97,2514,162],{"class":721},[97,2516,2517],{"class":103}," window.__LANDING__ ",[97,2519,954],{"class":721},[97,2521,2522],{"class":103}," manifest.landing ",[97,2524,633],{"class":721},[97,2526,2527],{"class":103}," manifest.admin;\n",[97,2529,2530,2533,2536,2538,2540,2542,2545,2548,2550,2552,2555],{"class":99,"line":114},[97,2531,2532],{"class":103},"files.js.",[97,2534,2535],{"class":158},"forEach",[97,2537,756],{"class":103},[97,2539,722],{"class":721},[97,2541,989],{"class":103},[97,2543,2544],{"class":1321},"f",[97,2546,2547],{"class":103},") { ",[97,2549,1855],{"class":158},[97,2551,756],{"class":103},[97,2553,2554],{"class":165},"\"modulepreload\"",[97,2556,2557],{"class":103},", f); });\n",[97,2559,2560,2563,2565,2567,2569,2571,2573,2575,2577,2579,2582,2585,2588],{"class":99,"line":130},[97,2561,2562],{"class":103},"files.css.",[97,2564,2535],{"class":158},[97,2566,756],{"class":103},[97,2568,722],{"class":721},[97,2570,989],{"class":103},[97,2572,2544],{"class":1321},[97,2574,2547],{"class":103},[97,2576,1855],{"class":158},[97,2578,756],{"class":103},[97,2580,2581],{"class":165},"\"preload\"",[97,2583,2584],{"class":103},", f, ",[97,2586,2587],{"class":165},"\"style\"",[97,2589,2590],{"class":103},"); });\n",[10,2592,2593,2594],{},"There's one part of this that's easy to get wrong: ",[22,2595,2596,2597,2600],{},"the CSS goes in as ",[14,2598,2599],{},"rel=\"preload\" as=\"style\"",", not as a stylesheet.",[2602,2603,2604,2612,2615,2669,2676,2687],"tip",{},[10,2605,2606],{},[22,2607,2608,2609,954],{},"Why not just insert a ",[14,2610,2611],{},"\u003Clink rel=\"stylesheet\">",[10,2613,2614],{},"Before Vite loads a dynamic entry at runtime, it takes care of that entry's CSS. Its preload helper has this check (Vite 5):",[88,2616,2618],{"className":2131,"code":2617,"language":2133,"meta":93,"style":93},"if (link.href === dep && (!isCss || link.rel === \"stylesheet\")) {\n  return; \u002F\u002F a stylesheet with this URL is already on the page: bail out, don't wait\n}\n",[14,2619,2620,2655,2665],{"__ignoreMap":93},[97,2621,2622,2624,2627,2630,2633,2635,2637,2639,2642,2644,2647,2649,2652],{"class":99,"line":100},[97,2623,1141],{"class":721},[97,2625,2626],{"class":103}," (link.href ",[97,2628,2629],{"class":721},"===",[97,2631,2632],{"class":103}," dep ",[97,2634,845],{"class":721},[97,2636,989],{"class":103},[97,2638,1813],{"class":721},[97,2640,2641],{"class":103},"isCss ",[97,2643,1430],{"class":721},[97,2645,2646],{"class":103}," link.rel ",[97,2648,2629],{"class":721},[97,2650,2651],{"class":165}," \"stylesheet\"",[97,2653,2654],{"class":103},")) {\n",[97,2656,2657,2659,2662],{"class":99,"line":114},[97,2658,1287],{"class":721},[97,2660,2661],{"class":103},"; ",[97,2663,2664],{"class":172},"\u002F\u002F a stylesheet with this URL is already on the page: bail out, don't wait\n",[97,2666,2667],{"class":99,"line":130},[97,2668,1185],{"class":103},[10,2670,2671,2672,2675],{},"If I add the stylesheet myself ahead of time, Vite sees it's \"already there\" and returns right away, which means ",[22,2673,2674],{},"the JS starts running before the CSS has finished loading",". The home page's intro animation measures elements when it mounts, and every one of those measurements is wrong if the styles aren't applied yet.",[10,2677,2678,2679,2682,2683,2686],{},"A ",[14,2680,2681],{},"rel=\"preload\""," link doesn't match that condition, so Vite still inserts its own stylesheet and waits for the ",[14,2684,2685],{},"load"," event. By then the file is already cached, so the wait is close to free. You get the warm cache and the correct execution order.",[10,2688,2689,2692],{},[14,2690,2691],{},"crossOrigin"," also has to match what Vite puts on its own tags, which is an empty string. If it doesn't, the two requests use different credentials modes and the browser won't reuse the cached response.",[10,2694,2695],{},"The manifest is deleted once it's been read. It never ships.",[10,2697,2698,2699,2702,2703,2706],{},"One more manifest gotcha. I first looked up the admin entry by its source path, ",[14,2700,2701],{},"src\u002Fmain.ts",", and it wasn't there. Something in the admin code imports the entry file back, so the bundler folded it into a shared chunk keyed by a hashed chunk name. I ended up finding it through the HTML entry's ",[14,2704,2705],{},"dynamicImports"," instead: it's whichever one isn't the home page.",[73,2708,2710],{"id":2709},"_7-verification-driving-a-real-browser-without-a-test-library","7. Verification: Driving a Real Browser Without a Test Library",[10,2712,2713],{},"All the risk in a change like this is at runtime. What does the address bar end up showing? Which resources got requested? Did hydration complain? Type checks and a green build can't tell you any of that.",[10,2715,2716,2717,2720,2721,2724,2725,2728],{},"I didn't reach for Puppeteer or Playwright. I talked to Chrome directly over the ",[22,2718,2719],{},"Chrome DevTools Protocol"," (CDP): launch the local Chrome with ",[14,2722,2723],{},"--headless=new --remote-debugging-port"," and send protocol commands over a WebSocket. On Node 20, ",[14,2726,2727],{},"--experimental-websocket"," turns on the built-in WebSocket client, so there's nothing to install:",[88,2730,2732],{"className":2131,"code":2731,"language":2133,"meta":93,"style":93},"const send = (method, params = {}) =>\n  new Promise(resolve => {\n    const id = ++seq;\n    pending.set(id, resolve);\n    ws.send(JSON.stringify({ id, method, params }));\n  });\n\nawait send(\"Page.navigate\", { url });\nconst state = await send(\"Runtime.evaluate\", {\n  expression: `JSON.stringify({ href: location.href, hasApp: !!document.getElementById(\"app\") })`,\n  returnByValue: true\n});\n",[14,2733,2734,2761,2778,2793,2804,2825,2830,2834,2848,2869,2879,2887],{"__ignoreMap":93},[97,2735,2736,2738,2741,2743,2745,2748,2750,2753,2755,2758],{"class":99,"line":100},[97,2737,1791],{"class":721},[97,2739,2740],{"class":158}," send",[97,2742,1234],{"class":721},[97,2744,989],{"class":103},[97,2746,2747],{"class":1321},"method",[97,2749,261],{"class":103},[97,2751,2752],{"class":1321},"params",[97,2754,1234],{"class":721},[97,2756,2757],{"class":103}," {}) ",[97,2759,2760],{"class":721},"=>\n",[97,2762,2763,2766,2769,2771,2774,2776],{"class":99,"line":114},[97,2764,2765],{"class":721},"  new",[97,2767,2768],{"class":788}," Promise",[97,2770,756],{"class":103},[97,2772,2773],{"class":1321},"resolve",[97,2775,1245],{"class":721},[97,2777,1035],{"class":103},[97,2779,2780,2783,2785,2787,2790],{"class":99,"line":130},[97,2781,2782],{"class":721},"    const",[97,2784,159],{"class":788},[97,2786,1234],{"class":721},[97,2788,2789],{"class":721}," ++",[97,2791,2792],{"class":103},"seq;\n",[97,2794,2795,2798,2801],{"class":99,"line":140},[97,2796,2797],{"class":103},"    pending.",[97,2799,2800],{"class":158},"set",[97,2802,2803],{"class":103},"(id, resolve);\n",[97,2805,2806,2809,2812,2814,2817,2819,2822],{"class":99,"line":150},[97,2807,2808],{"class":103},"    ws.",[97,2810,2811],{"class":158},"send",[97,2813,756],{"class":103},[97,2815,2816],{"class":788},"JSON",[97,2818,280],{"class":103},[97,2820,2821],{"class":158},"stringify",[97,2823,2824],{"class":103},"({ id, method, params }));\n",[97,2826,2827],{"class":99,"line":182},[97,2828,2829],{"class":103},"  });\n",[97,2831,2832],{"class":99,"line":213},[97,2833,1282],{"emptyLinePlaceholder":1281},[97,2835,2836,2838,2840,2842,2845],{"class":99,"line":581},[97,2837,1556],{"class":721},[97,2839,2740],{"class":158},[97,2841,756],{"class":103},[97,2843,2844],{"class":165},"\"Page.navigate\"",[97,2846,2847],{"class":103},", { url });\n",[97,2849,2850,2852,2855,2857,2859,2861,2863,2866],{"class":99,"line":587},[97,2851,1791],{"class":721},[97,2853,2854],{"class":788}," state",[97,2856,1234],{"class":721},[97,2858,1527],{"class":721},[97,2860,2740],{"class":158},[97,2862,756],{"class":103},[97,2864,2865],{"class":165},"\"Runtime.evaluate\"",[97,2867,2868],{"class":103},", {\n",[97,2870,2871,2874,2877],{"class":99,"line":943},[97,2872,2873],{"class":103},"  expression: ",[97,2875,2876],{"class":165},"`JSON.stringify({ href: location.href, hasApp: !!document.getElementById(\"app\") })`",[97,2878,1300],{"class":103},[97,2880,2881,2884],{"class":99,"line":968},[97,2882,2883],{"class":103},"  returnByValue: ",[97,2885,2886],{"class":788},"true\n",[97,2888,2889],{"class":99,"line":977},[97,2890,1987],{"class":103},[10,2892,2893,2894,2897],{},"Next to it runs a static server, about twenty lines long, that serves the build output ",[22,2895,2896],{},"from a subdirectory and from the domain root at the same time",". That covers both the test setup and production, including production's habit of serving the home page for unknown paths. The server also logs every request path, which is how I can actually back up a claim like \"zero home page image requests on an admin URL.\"",[10,2899,2900],{},"I ran nine URLs through it, and for each one read back the final address, the title, the DOM state, and any console errors:",[302,2902,2903,2913],{},[305,2904,2905],{},[308,2906,2907,2910],{},[311,2908,2909],{},"Scenario",[311,2911,2912],{},"What I checked",[324,2914,2915,2926,2940,2951,2959,2969,2977],{},[308,2916,2917,2920],{},[329,2918,2919],{},"Home page, once in a subdirectory and once at the root",[329,2921,2922,2923,2925],{},"No ",[14,2924,16],{}," in the address; container hydrated; no console errors; no broken images in the subdirectory",[308,2927,2928,2937],{},[329,2929,2930,2931,234,2934],{},"Old URLs ",[14,2932,2933],{},"#\u002Flanding\u002Fhome",[14,2935,2936],{},"\u002F?utm=x#\u002F",[329,2938,2939],{},"Address cleaned up, query string intact",[308,2941,2942,2948],{},[329,2943,2944,2945],{},"Admin URL ",[14,2946,2947],{},"#\u002Flogin",[329,2949,2950],{},"Home page container gone; zero requests for home page images, posters, or styles",[308,2952,2953,2956],{},[329,2954,2955],{},"Clicking through to admin from the home page",[329,2957,2958],{},"One reload, then the login page",[308,2960,2961,2964],{},[329,2962,2963],{},"Navigating to the root path from inside admin",[329,2965,2966,2967],{},"Full reload back to the home page, no ",[14,2968,16],{},[308,2970,2971,2974],{},[329,2972,2973],{},"The legal page inside admin",[329,2975,2976],{},"Shared header and footer links work",[308,2978,2979,2984],{},[329,2980,2981,2982],{},"Short link ",[14,2983,1099],{},[329,2985,2986],{},"Still reaches the mobile page instead of being treated as the home page",[10,2988,2989,2990,2993],{},"Last, I used ",[14,2991,2992],{},"Page.captureScreenshot"," to grab three screenshots and looked at them myself. That's where pitfall 4 turned up.",[73,2995,2997],{"id":2996},"_8-where-this-approach-falls-short","8. Where This Approach Falls Short",[10,2999,3000],{},"None of this is free, so here's what it costs.",[10,3002,3003],{},[22,3004,3005],{},"What it doesn't fix",[39,3007,3008,3014,3020],{},[42,3009,3010,3013],{},[22,3011,3012],{},"Users don't see the page any sooner."," The hero's intro animation waits for JS to add a state class before it fades in. Combine that with the hiding from pitfall 1, and content shows up at about the same moment it did before. Prerendering decides whether content can be read, not how quickly it's seen. Page experience metrics are a separate job.",[42,3015,3016,3019],{},[22,3017,3018],{},"Only one page benefits."," The legal page and everything else are still hash routes.",[42,3021,3022,3025,3026,3029],{},[22,3023,3024],{},"Unknown paths still return 200."," The static host's fallback hasn't changed. A ",[14,3027,3028],{},"canonical"," tag tells search engines the domain root is the real address.",[10,3031,3032],{},[22,3033,3034],{},"What it adds",[39,3036,3037,3046,3052,3066,3072],{},[42,3038,3039,3042,3043,3045],{},[22,3040,3041],{},"The entry HTML got heavier."," ",[14,3044,70],{},", which is only a shell, went from about 4 kB to about 98 kB, or roughly 17 kB gzipped, and the extra home page markup is no use to admin users. My first version was actually 165 kB (40 kB gzipped), and two trims brought it down. First, the contact modal, which only appears on click, now renders in the browser only. It's worthless to crawlers, yet its template is packed with inline icons. Second, the home page's small images are no longer inlined as data URIs. As separate files they also get lazy loading for free. What's left is only paid on a full page load, since in-app route changes never re-request the HTML. Next to the roughly 1.8 MB of JavaScript the admin app loads up front (uncompressed, about 590 kB gzipped), it's a small fixed cost.",[42,3047,3048,3051],{},[22,3049,3050],{},"The home page and admin still ship together."," Fixing a typo on the home page means releasing the entire admin app. If the home page is going to grow into a multi-page content site, this is the wrong approach. At that point, split it into its own project and accept that the admin app has to move.",[42,3053,3054,3057,3058,3061,3062,3065],{},[22,3055,3056],{},"Home page components now come with rules."," They have to render in Node, which means no top-level ",[14,3059,3060],{},"window"," or ",[14,3063,3064],{},"document",", and nothing that differs between server and client, like random numbers or the current time. The build fails if you break this, but whoever edits those components needs to know the rule going in.",[42,3067,3068,3071],{},[22,3069,3070],{},"There's build code to re-test on every bundler upgrade."," The plugin leans on the shape of the manifest and on how the SSR build treats a relative base. Neither is a stable public contract.",[42,3073,3074,3077,3078,3080],{},[22,3075,3076],{},"The routing check lives in two places."," An inline script can't ",[14,3079,1643],{},", so the hash rule is written once in the HTML and once in TypeScript, with nothing but comments keeping them in sync.",[73,3082,3084],{"id":3083},"_9-takeaways","9. Takeaways",[253,3086,3087,3096,3102,3108,3114],{},[42,3088,3089,3092,3093,3095],{},[22,3090,3091],{},"Work out which problem you actually have before you touch anything."," The ask was \"get rid of the ",[14,3094,16],{},".\" The goal was \"be readable by search engines.\" The first is just one prerequisite for the second. Take the ask literally and you end up with a lovely clean URL on a page crawlers still see as an empty shell.",[42,3097,3098,3101],{},[22,3099,3100],{},"Flip a constraint around and it often turns into the design."," \"The root path can only serve one file\" killed two obvious options and pointed directly at a third: make that file do two jobs. When a constraint has you stuck, it's worth asking what things would look like if the constraint were part of the design.",[42,3103,3104,3107],{},[22,3105,3106],{},"What you add shouldn't cost anything for the people who don't use it."," Home page visitors and crawlers benefit here, but the change lands in an entry point everyone shares. Getting preloading back, lazy-loading the images, and deferring the posters are all there so admin users don't pay for a feature that has nothing to do with them. When you're weighing an approach, give \"impact on unrelated paths\" a column of its own.",[42,3109,3110,3113],{},[22,3111,3112],{},"A silent failure is worse than a loud one."," Failing the build when prerendering fails, and refusing to patch stale output when the build fails, both exist to surface problems before release. That matters most for SEO work, because nobody files a bug when it breaks.",[42,3115,3116,3119],{},[22,3117,3118],{},"Screenshots catch what assertions miss."," That 8px white border sailed through every automated check. If a change touches rendering, get a person to look at the actual page, even if that person is you.",[2349,3121,3122],{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sByVh, html code.shiki .sByVh{--shiki-light:#22863A;--shiki-default:#85E89D;--shiki-dark:#85E89D}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .sQeJH, html code.shiki .sQeJH{--shiki-light:#032F62;--shiki-default:#DBEDFF;--shiki-dark:#DBEDFF}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .sAxt1, html code.shiki .sAxt1{--shiki-light:#22863A;--shiki-light-font-weight:bold;--shiki-default:#85E89D;--shiki-default-font-weight:bold;--shiki-dark:#85E89D;--shiki-dark-font-weight:bold}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}",{"title":93,"searchDepth":114,"depth":114,"links":3124},[3125,3127,3128,3129,3134,3140,3141,3142,3143],{"id":75,"depth":114,"text":3126},"1. Where It Started: Is # Really the Problem?",{"id":363,"depth":114,"text":364},{"id":527,"depth":114,"text":528},{"id":687,"depth":114,"text":688,"children":3130},[3131,3132,3133],{"id":692,"depth":130,"text":693},{"id":1195,"depth":130,"text":1196},{"id":1775,"depth":130,"text":1776},{"id":2028,"depth":114,"text":2029,"children":3135},[3136,3137,3138,3139],{"id":2032,"depth":130,"text":2033},{"id":2117,"depth":130,"text":2118},{"id":2251,"depth":130,"text":2252},{"id":2287,"depth":130,"text":2288},{"id":2462,"depth":114,"text":2463},{"id":2709,"depth":114,"text":2710},{"id":2996,"depth":114,"text":2997},{"id":3083,"depth":114,"text":3084},"2026-11-26","Our marketing home page lived at #\u002Flanding\u002Fhome inside an admin SPA, so crawlers saw an empty shell. Here's why I ended up serving two apps from a single index.html and prerendering one of them at build time, plus the build plugin behind it, four things that bit me, and how I got preloading back after the entry points became dynamic imports.","md",null,"\u002Farticles\u002Fspa-hash-seo-prerender.svg",{},"\u002Farticles\u002Fspa-hash-seo-prerender",4.5,"17",{"title":5,"description":3145},{"loc":3150},"articles\u002Fspa-hash-seo-prerender",[3157,3158],"Frontend","Engineering","NLpNmjWUHvqr5RpCs1KC_6L67bKZCviEFzlRl6WYOjc",1795761651129]