DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Our whole public folder is six files and 22,348 bytes, and one of them is 32 bytes of proof we own the domain

In a Next app, public/ is the escape hatch: anything you drop in there is served from the root of your domain, untouched. It is where favicons, robots files, logos, Open Graph images and marketing PDFs usually pile up over a year.

Nakodo has 76 public pages, 76 social cards, a sitemap, a robots file, a manifest, two llms files and an RSS feed. I went to look at what that adds up to on disk:

$ find public -type f | xargs ls -l | awk '{print $5, $9}'
11669 public/icon-512.png
 4081 public/icon-192.png
 3785 public/apple-touch-icon.png
 2155 public/favicon.ico
  626 public/icon.svg
   32 public/16d8efaf91714b41835b07bc3a740f9b.txt
Enter fullscreen mode Exit fullscreen mode

Six files. 22,348 bytes. Five of them are the same bird at five sizes, and the sixth is 32 bytes of hexadecimal.

Everything you would expect is a route

The things you would normally reach for public/ to hold are all generated, which is the actual reason the folder is this small:

On the live site How it exists
/sitemap.xml sitemap.ts, mapped from the content registry
/robots.txt robots.ts
/manifest.webmanifest manifest.ts
/llms.txt and /llms-full.txt two route handlers, 574,629 bytes of the second
/blog/feed.xml a route handler
76 social cards, one per page one dynamic image route
Every illustration on every page React components emitting inline SVG

There is not one photograph on the whole site, and no <img>, <picture> or <canvas> element is rendered on any public page. The line art is drawn in code. That decision is why the folder is six files instead of sixty, and it is the single biggest structural difference between this repo and every other marketing site I have built.

The 32 byte file

$ curl -s https://nakodo.app/16d8efaf91714b41835b07bc3a740f9b.txt
16d8efaf91714b41835b07bc3a740f9b
Enter fullscreen mode Exit fullscreen mode

The filename is the content. That is the IndexNow key pattern: you generate a hex string, serve it at /<key>.txt, and then your submissions to the IndexNow endpoint carry the same string, which proves to the search engine that whoever is announcing URLs for this host can also write files to its root.

It is a nice piece of protocol design because it needs no account, no token exchange and no callback. It is also the one thing in the folder that genuinely has to be a static file: everything else in public/ could be a route if I wanted it to be, but a verification file that lives at an arbitrary root path is exactly what public/ is for.

It has one consequence that caught me out. Our auth boundary is an allowlist of public paths, and anything not on the list redirects to the login page. A hex filename matches no pattern, so it needs its own line:

"/16d8efaf91714b41835b07bc3a740f9b.txt", // the IndexNow key file (src/lib/seo/indexnow.ts)
Enter fullscreen mode Exit fullscreen mode

Without the comment, that line is unexplainable, and the first person to tidy up unused constants would delete it and quietly break search engine submissions in a way that produces no error anywhere.

The bird is spelled twice

The one drawing in the folder is icon.svg, which is 626 bytes:

<svg xmlns="http://www.w3.org/2000/svg" viewBox="-0.3 -0.3 15.6 15.6">
  <style>
    path { fill: #004783 }
    @media (prefers-color-scheme: dark) { path { fill: #a1cdff } }
  </style>
  <path d="m6 15l-1.87-2.06l-2.63 1.12l2.02-2.94c.5-.74..."/>
</svg>
Enter fullscreen mode Exit fullscreen mode

The same 450 character path is also a constant in a React component:

const BIRD = "m6 15l-1.87-2.06l-2.63 1.12l2.02-2.94c.5-.74...";

export function Mark({ className, inverted = false }: { className?: string; inverted?: boolean }) {
  return (
    <svg viewBox="-0.3 -0.3 15.6 15.6" className={cn("size-8 shrink-0", className)} aria-hidden="true">
      <path d={BIRD} fill={inverted ? "var(--panel-foreground)" : "var(--primary)"} />
    </svg>
  );
}
Enter fullscreen mode Exit fullscreen mode

Those two cannot be one thing, and the reason is the same reason a webmanifest cannot hold a CSS variable. A favicon is loaded by the browser outside the document: there is no stylesheet in scope, no custom properties, no cascade. So the file carries #004783 and a prefers-color-scheme block, which is the only theming mechanism available to a standalone SVG, while the component carries var(--primary) and inherits our whole colour system including the panel inversion.

The cost is that the geometry exists in two places with nothing comparing them. If I redraw the bird in the component, the favicon keeps the old one, and no test, build step or lint rule will say a word. On the home page the component's copy of the path appears six times in the served HTML, next to a <link rel="icon"> pointing at a file containing a seventh copy that may or may not agree with them.

The fix I like is generating the file: write the path once in TypeScript, and let a route emit the SVG with the hex pair resolved from the same ramp the stylesheet uses. That converts the last drawing in public/ into a route too, and leaves the folder holding four PNGs and a hex string.

Files you put there get the opposite cache header

This is the part I would not have predicted, and it is worth checking on your own site. The framework's own output is cached forever:

$ curl -sI https://nakodo.app/_next/static/immutable/chunks/<hash>.css | grep -i 'cache-control\|age'
cache-control: public,max-age=31536000,immutable
age: 288850
Enter fullscreen mode Exit fullscreen mode

A file you put in public/ is not:

$ curl -sI https://nakodo.app/favicon.ico | grep -i 'cache-control\|age\|etag'
cache-control: public, max-age=0, must-revalidate
etag: "..."
age: 288851
Enter fullscreen mode Exit fullscreen mode

max-age=0, must-revalidate is the same header our HTML pages carry. The reasoning is sound: /_next/static/ paths contain a content hash, so the URL changes whenever the bytes change and the file can be immortal, whereas /favicon.ico is a stable URL whose contents could change on any deploy, so the platform refuses to let a browser hold it without asking.

The practical effect is that every one of our six static files is revalidated by every returning visitor. Each of those revalidations is a 304 with no body, so it costs about 190 bytes rather than 22 KB, and the age of 288,851 seconds shows the CDN itself is holding them across more than three days without going back to origin. It is cheap. It is just not free, and "I put it in public so it is cached" is not what is happening.

If you want long-lived caching for these, the lever is a header rule in your platform config keyed on the path, which is a decision to promise those bytes will not change. For a favicon that promise is easy to break by accident, so we have not made it.

The fonts that are committed and not in public

One more thing lives in the repository as a binary and is deliberately not in the static folder:

$ ls -l src/assets/fonts/
110708 Archivo-Regular.ttf
111872 Archivo-SemiBold.ttf
 56072 Besley-SemiBold.ttf
129916 IBMPlexMono-Medium.ttf
Enter fullscreen mode Exit fullscreen mode

408,568 bytes, eighteen times the size of public/, and not one byte of it ever reaches a visitor. Browsers get woff2 subsets through next/font. Those four TTFs exist because the social card renderer runs on the server and needs real font buffers to measure and draw text, and it reads three of the four. Archivo-Regular.ttf is read by nothing, which I only noticed while writing this paragraph, and is the most honest finding in the post.

What I am changing

  • Delete Archivo-Regular.ttf, or start using it. It is 110,708 bytes of repository that nothing opens.
  • Generate icon.svg from the BIRD constant so the bird is written once, with the hex pair derived from the colour ramp rather than typed.
  • Leave the cache headers alone, and write the reason down next to the icon list so the next person does not "fix" it.

The thing I would take to another project is the inventory itself. find public -type f is a ten second audit that tells you how much of your site is files somebody dropped in a folder and how much is output your code is responsible for. Six files felt like a mistake until I listed what was not in there.

Top comments (0)