26 October 2026
What Are Static Files? A Practical Guide to Serving Web Assets

TL;DR
Static files are stored assets delivered without generating new contents for each request. CSS, browser JavaScript, images, fonts and PDFs are common examples. A browser asks for a URL; a server or host maps it to a public asset and returns its bytes with an appropriate content type and cache policy. HTML may be static or generated per request. Keep private uploads outside the public asset path.
A web page can look like one thing in a browser while arriving as several HTTP responses. The document refers to a stylesheet, a script and perhaps a logo; the browser requests each separately. Understanding where those files come from is useful when a page has no styling, a deployment serves an old script, or a customer document accidentally becomes public.
For a TypeScript team, I would start with a simple question: Which component owns each requested URL? It might be a static host, a reverse proxy or a web application process. The file's location in your source tree, its location after a build and its browser URL are related, but they are not necessarily identical.
Table of contents
- What counts as a static file?
- How a static-file request reaches the browser
- Static assets beside a db3.ai application
- Cache static assets without trapping users on an old release
- Public assets versus user uploads
- Frequently asked questions
- Sources
- Recommended Reads
What counts as a static file?
A static file has content prepared before a particular request and delivered as an asset rather than composed anew from application data for that request. A logo at /images/logo.png, a stylesheet at /assets/site.css, a built JavaScript bundle and a downloadable public PDF all qualify when served this way. Express's static-file documentation uses images, CSS and JavaScript as typical examples; Vite's asset guide also covers how a build processes referenced images and fonts.
Static does not mean permanent. You can replace a logo in a later release. It means the server is not assembling a different logo for every incoming request. Nor does static mean noninteractive: a prebuilt JavaScript file can run an interactive application after the browser downloads it.
HTML depends on its delivery path. A prebuilt index.html served from a directory is a static file. HTML assembled by a server-side renderer for the current request is a dynamic response, even if the result links to the same static CSS and JavaScript. An API response generated from a database is dynamic too. The distinction concerns how the response is produced, not its filename or whether the browser can display it.
| Browser requests | Typical owner | What determines the response |
|---|---|---|
/assets/site.css |
Public asset host or static-file handler | A stored stylesheet at a configured path |
/products/42 |
Application route or SSR renderer | Route handling and, often, request-specific data |
/api/products/42 |
API route | Application logic and data |
/account/invoice.pdf |
Authorized download route | Permission check followed by access to stored bytes |
That last PDF could be delivered as bytes from storage, but calling it a file does not make it appropriate for public static serving. Access control is a separate decision.
How a static-file request reaches the browser
Imagine the browser finds a reference to /assets/site.css in an HTML document. It makes an HTTP request for that URL. The host or application matches /assets/ to a configured public directory, finds site.css, and returns a response with the bytes and headers. The browser uses the Content-Type to interpret the response and the caching headers to decide when a stored copy can be reused. If the file is missing, the asset request should fail as a missing asset, rather than silently return an unrelated HTML page.

There are several independent mappings in that short journey. A developer might edit client/styles/site.css, the build might emit dist/client/assets/site.a1b2.css, and the host might expose it at /assets/site.a1b2.css. Those paths are illustrative, not a promise about any framework's default output. What matters is that the URL embedded in the delivered HTML resolves to a file in the deployed build, through the component that actually handles the request.
Express 5 offers a concrete example of the mapping. When an app mounts its public directory at /static, the browser requests a file through /static/...; public is the filesystem directory name, not part of the URL. Express also notes that a relative directory depends on the process's working directory. This demonstrates the principle, not an instruction to add Express middleware to every TypeScript application. See the Express 5 static-file guide for its exact behavior.
Response type is another independent concern. According to MDN's media-type guide, CSS should be sent as text/css, JavaScript as text/javascript, HTML as text/html, and a PNG as image/png. Sending a stylesheet as text/plain can cause a browser to ignore it. A particularly confusing failure occurs when a catch-all HTML route returns a page with status 200 for a missing .js URL: the network request appears successful, but the browser receives HTML where it expected a script.
Build assets and public-directory assets are not the same path
A build tool may transform imported assets and give them new names. In Vite, referenced assets become part of the build graph and can receive hashed names, while files in its public directory are copied to the build output without hashing and are served from the root in development. Vite recommends imports for ordinary referenced assets and reserves public for cases such as a required unchanged filename. These are Vite-specific rules, not a universal requirement that every project have a public directory.
I would use a build-managed URL for an image whose name may change when its content changes, and an intentionally stable public path for a file that must keep a fixed name. Then I would inspect the production artifact. A path that works through a development server does not establish that the built file was packaged or that the production server exposes it under the same prefix. If the app lives under /product/ instead of /, also inspect the build's base path: Vite's production guide documents its base setting for rewriting generated asset references at a nested public path.
Static assets beside a db3.ai application
The separation between pages and files also matters in a unified TypeScript runtime. The db3.ai SSR guide says an application owns its pages, router, data and hydration, while the optional Vite SSR adapter handles its development integration, production build loading and optional static assets. Its SSR API reference exposes staticAssets as a directory and URL-prefix pair, with routes specifying the pages the SSR adapter owns. This does not imply that the framework automatically publishes an arbitrary directory or that every browser URL becomes an SSR route.
Here is a configuration excerpt, based on the documented Vite adapter options, that makes the two kinds of URL ownership visible:
import Fastify from 'fastify';
import { fastifyViteSsr } from '@db3.ai/app/ssr/vite';
const server = Fastify();
await server.register(fastifyViteSsr({
root: import.meta.dirname,
routes: ['/blog', '/blog/*'],
staticAssets: {
prefix: '/site-assets/',
directory: 'dist/client/site-assets',
},
}));
The import, adapter and option names match the published db3.ai SSR API reference. The excerpt is not a runnable application on its own: your application must provide its Vite configuration, server renderer, document template, matching client and server builds, actual asset files, route ownership and process lifecycle. Check that the emitted URLs really use /site-assets/, that the named directory is in the deployed artifact, and that API requests are not captured by a page fallback. I have not run this excerpt or tested a particular deployment.
For setup, the db3.ai installation guide describes Node.js 24 for its walkthroughs, Fastify 5 for its HTTP examples, and matching maintainer-supplied App and Pure preview tarballs. At the time of review, the guide says the packages are not yet published to npm; do not replace that preview setup with an assumed public install command. None of these runtime pieces removes the need to decide which files may be public.
Cache static assets without trapping users on an old release
Caching is useful because a browser or shared cache can reuse an asset without fetching the same bytes for every page visit. It also creates a deployment obligation: if you overwrite /assets/site.js while a cache still regards its old copy as fresh, different clients may see different releases under the same URL.
A common solution is to change the URL when the content changes, for example by placing a build hash in the filename. A cache can then retain the old asset at its old URL while a new HTML document points to a new URL. MDN's Cache-Control reference describes versioned URLs and immutable for resources that will not change while fresh. Use a long freshness lifetime only if the asset URL truly identifies bytes you will not replace; plan how older chunks remain available to already-open pages during rollout.

HTML often deserves a different policy because it tells the browser which asset URLs to fetch. Cache-Control: no-cache permits storage but requires validation before reuse; it does not mean the response cannot be stored. no-store asks caches not to store it. MDN defines those directives separately, and Vite's production guide specifically recommends no-cache on HTML in a deployment scenario where old HTML could reference removed chunks. For personalized responses, apply a policy appropriate to the data, rather than treating every HTML response as public. The db3.ai SSR lab deliberately uses private, no-store for its example response.
Public assets versus user uploads
A public asset directory is appropriate only for files every intended visitor may fetch. A tenant's invoice, an uploaded contract or a generated report usually needs a different path: store bytes outside the publicly exposed asset root, look up the file's owner, authorize the requester, and then deliver permitted bytes through an application-controlled route or another deliberately scoped delivery mechanism. Even if an upload never changes after it is stored, its fixed contents do not make it public.
Keep source maps, server bundles, configuration, credentials and private exports out of the public directory as well. A directory named private inside an exposed root is not automatically protected. Similarly, a client-side router's fallback to index.html is a route choice, not a file-access policy: missing APIs, missing images and private downloads should not be converted into successful public HTML responses.
Here is my quick decision check for an individual asset:
- Audience: Can anyone with the public URL read it? If not, use an authorization-aware delivery path.
- Production form: Does the exact file exist before requests, or must the server assemble a response per request?
- URL ownership: Which host, proxy or application route answers the browser URL, and which deployed file or storage key backs it?
- Response contract: Does the response have the expected media type, missing-file status and cache policy?
- Release behavior: When bytes change, will the URL change too, or will caches need to validate before reuse?
These questions are more reliable than deciding by extension. Two PDFs can require entirely different treatment: a public product brochure can be a static download, while a customer invoice must remain behind an access check.
Frequently asked questions
Is HTML a static file?
It can be. HTML served as a prebuilt file is static delivery. HTML rendered from application logic for each request is dynamic, even if it loads static CSS and JavaScript. Inspect how the response was produced rather than its .html suffix.
Are uploaded images static files?
Their bytes may be stored and later delivered unchanged, but that does not tell you whether they are public. A publicly licensed avatar and a private identity document need different access rules. Decide visibility and retention before putting either into a publicly served directory.
Why do static files work locally but return 404 after deployment?
The production build may have renamed or omitted an asset, the deployed package may exclude the output directory, or the browser may request a different public prefix from the one the host serves. Check the exact request URL and status in the browser's Network panel against the built artifact and the production mount. If a JavaScript request returns HTML instead, inspect your fallback routing and content type.
Next step: Pick one CSS, one script and one image URL from your deployed page. Trace each from build output to public prefix to browser response, then test a missing asset and a private-file request. If you are using db3.ai, compare that boundary with the SSR guide and its static asset options before exposing a directory.
Sources
- Express 5: Serving static files
- Vite: Static asset handling
- Vite: Building for production
- MDN: Media types
- MDN: Cache-Control header
- db3.ai: Render public HTML
- db3.ai: SSR API reference
- db3.ai: Install packages in an existing project
Recommended Reads
- Staticfile vs. Static Files: Find the Right Setup for Your Web App, if you encountered a deployment file literally named
Staticfileor need a deeper asset-routing diagnosis. - File Storage in TypeScript: 4 Options Compared for SaaS Uploads, for the private-upload and storage choices that do not belong in a public asset directory.