db3.aiVisit main site

19 October 2026

Staticfile vs. Static Files: Find the Right Setup for Your Web App

TL;DR

“staticfile” is not one universal web feature. It might mean a static asset, a platform-specific file named Staticfile, or an API with a similar name. First identify your deployment platform and application runtime. Then map the built asset directory to public URLs, decide who handles browser routes, and keep private files and server-rendered responses outside the public asset bucket.

A search for staticfile can send a TypeScript developer in several directions. A deploy log may be asking for a file with an exact name. A browser error may concern a missing JavaScript bundle. A framework reference might describe a helper function, not a hosting feature. Those problems call for different fixes.

I use one question to separate them: What is supposed to receive the HTTP request? If the answer is an existing file, inspect asset serving. If it is a server-rendered page or API response, inspect application routes. If deployment tooling mentions Staticfile with a capital S, inspect that platform's buildpack or provider rules.

Table of contents

What is a static file, and what is “Staticfile”?

A static file is an asset delivered from stored bytes rather than assembled for each request. HTML documents, CSS, browser JavaScript, images, fonts and downloadable PDFs can all fit. “Static” describes the delivery path, not whether JavaScript later makes the page interactive. A client-side application may download a static HTML shell and bundle, then fetch personalized data from an API.

The unqualified spelling staticfile does not identify a standard file format or a single server method. These are three useful interpretations:

What you encountered What it means Where to look
“Serve static files” or /assets/app.js Deliver build output or public files over HTTP Your framework, reverse proxy or host's asset documentation
A file literally named Staticfile A platform-specific deployment or provider convention That platform's buildpack and deployment documentation
staticFile() or StaticFiles in code A named API belonging to a particular library That library's versioned API reference

Three distinct meanings of staticfile: an asset, a deployment convention, and an application rendering route

Names alone can mislead. Remotion's staticFile() turns a file under its project's public/ directory into a URL, including support for subdirectory deployment. FastAPI's StaticFiles mounts a directory under a URL path; it comes from Starlette. Neither is a Cloud Foundry deployment file. Starlette documents its own directory and HTML-mode options, while Django's staticfiles guide addresses collection and delivery through Django's settings and deployment workflow. Similar names do not imply interchangeable setup.

When Staticfile means a deployment convention

Cloud Foundry uses an exact-name Staticfile in an app's build directory to detect its Staticfile buildpack. The file can be empty or contain settings. The buildpack provides NGINX to serve a static site or frontend whose backend runs elsewhere. This is not a way to run your TypeScript API or an SSR server inside the static site. Cloud Foundry's Staticfile buildpack guide documents detection, configuration and push behavior.

For example, suppose your frontend build places index.html and its assets inside dist/. Place Staticfile at the deployment root, include dist/ in the deployment, and give it these lines:

root: dist
pushstate: enabled

Here root selects the directory to serve. pushstate supports clean browser URLs for a client-side router; use it only if your deployed site actually needs that routing model. Build the frontend before pushing, then confirm that dist/index.html exists in the directory being staged. On a Cloud Foundry installation with the system buildpack, pushing from that application root uses its detection rules; otherwise follow its documented explicit-buildpack path. A file named Staticfile in your source tree does not guarantee that your host will interpret it.

The name also appears in Nixpacks' Staticfile provider, which serves a detected directory with NGINX. Its detection rules include more than an exact-name file. Read the provider used by your deployment rather than copying Cloud Foundry settings into unrelated tooling.

When the issue is ordinary asset serving

If a browser requests /assets/app.js, find the process or service that owns that URL. Follow the path from source asset to build output to deployed directory to public URL. Those locations often have different names. A successful local build proves that a file was produced locally, not that the production artifact includes it or serves it under the expected prefix.

For example, Express 5's static-file guide shows that mounting a public directory at /static makes a file inside it accessible below /static, without putting public in the browser URL. Its guide also warns that relative directories depend on the process working directory. That is Express behavior, not an implied db3.ai route or a universal property of every server.

A TypeScript frontend built with Vite has another boundary: Vite's production build documentation says its build produces assets suitable for static hosting. For deployment under a nested path, its base setting rewrites generated asset references. A page available at /product/ can still fail if its HTML asks the browser for /assets/app.js at the domain root instead of the deployed subpath.

Client-side routing is a separate decision. A request for /product/settings might need an HTML-shell fallback so the browser router can take over. An API request for /api/settings, a missing image, and an SSR route should not automatically receive that same HTML shell. Restrict fallbacks to the routes the frontend actually owns. Otherwise a 404 becomes a misleading 200 containing HTML, and the browser may report a confusing script or JSON parse error.

How this boundary works in a db3.ai application

In db3.ai, the documented @db3.ai/app package is an application runtime, not Cloud Foundry's Staticfile buildpack. Its optional SSR guide keeps the application responsible for pages, router, data and hydration. The Vite/Fastify SSR adapter handles development integration, production bundles and optional static asset registration. An explicit SSR route does not make all browser routes server-rendered.

The following configuration excerpt adapts the example in db3.ai's SSR service reference and uses the documented staticAssets options. It describes a public asset directory for a Vite SSR web process, not a generic file-upload endpoint:

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 root is the application root, routes identifies pages the SSR adapter owns, and staticAssets pairs a public URL prefix with a built client directory. This is not a stand-alone executable app: supply your own Vite configuration, HTML template, server renderer and client/server builds; verify the directory, generated URLs, API route ownership and process startup and shutdown in your deployment. The installation guide currently describes matching preview package tarballs rather than an npm-published package, and its walkthrough uses Node.js 24 and Fastify 5. I have not executed this adapted excerpt or verified a particular production build.

Do not put private uploads, reports or the SSR server bundle in that public asset directory. Public static delivery has no user-specific authorization check by default. Keep protected downloads behind an authenticated application route and a suitable storage policy. Likewise, request-specific SSR HTML needs a cache policy appropriate to its data; the db3.ai SSR guide's public-page lab explicitly demonstrates a private, no-store response, not a blanket rule for all pages.

A six-point deployment check for TypeScript teams

Before selecting a setup guide, write down the following. It turns an ambiguous search into a concrete deployment contract:

  1. Platform and runtime: Is this Cloud Foundry, Nixpacks, a static host, a reverse proxy, or your running Node.js application? Identify which component answers each URL.
  2. Build and artifact: Where does index.html land after the production build? Are the CSS and JS chunks present in the actual deployed package or image?
  3. Directory and prefix: Which directory is exposed, and under which public URL? Check case, trailing slash, subdirectory base and filesystem root independently.
  4. Route ownership: Which paths return files, which use a client-side HTML fallback, which render HTML on the server, and which are APIs? Test unknown paths in every group.
  5. Caching: Give versioned public assets and revisable HTML deliberate policies. Vite notes that an HTML document cached across deployments can reference chunks that have since been removed; its build guide recommends Cache-Control: no-cache for that HTML scenario.
  6. Visibility: Is each file intentionally public? An uploaded tenant document is not made safe by placing it in a folder named private beneath a publicly served root.

Comparing a deployed build folder with browser asset requests to diagnose missing static files

This check is especially useful when local development works but production fails: dev-server behavior, artifact packaging and the public server are different layers. Test the real deployed URL, not just the dev server.

Troubleshoot 404s and broken routes

A CSS or JavaScript request returns 404: Inspect the browser's Network tab for the exact request URL. Compare it with the deployed file path and the server's mounted prefix. If the file is missing from the artifact, fix the build or copy step; if it exists but the URL is wrong, fix the base path or serving configuration.

A deep link works after clicking but fails on refresh: The client router may own the route while the server sees an unknown URL. Configure a fallback for the intended SPA surface only. Do not redirect missing /api/ paths or missing built assets to index.html.

The site works at / but not at /product/: Check absolute URLs in HTML, Vite's base, router base and the host's mount path together. Changing only the server's folder does not rewrite asset references already emitted by the build.

The response is 200 but the page is broken: Check Content-Type and the response body. If a JavaScript URL returns HTML, a too-broad fallback likely hid an actual missing asset. If SSR HTML includes a client script that is missing, confirm the client build and its public asset directory travel together.

Frequently asked questions

Is HTML always a static file?

No. A prebuilt index.html served from disk is static delivery. HTML assembled for a request by an SSR renderer is a dynamic response, even when both pages later load the same CSS or browser JavaScript.

Do I need a Staticfile for every TypeScript application?

No. Create that exact-name file only when your deployment provider documents the convention and your deployment uses that path. For ordinary asset serving, follow the application framework or hosting platform's own instructions.

Can one app use static assets and SSR together?

Yes. Public built assets can have their own URL prefix while selected page routes are rendered on the server. In the documented db3.ai Vite adapter, staticAssets defines an optional production asset mapping and routes names the SSR-owned pages. Your application still supplies the renderer and client build.

Next step: Identify the component that serves your failing URL, then run the six-point check against a real production build. If you are using db3.ai, start with the SSR guide and its explicit route boundary; use its API reference to align your static asset path with your application build.

Sources