GPN BusinessDiscoverer

Documentation/ GPN BusinessDiscoverer/ gpn-yp-site-worker

Remix on Cloudflare Workers

How Remix provides SSR, loaders, actions, and progressive enhancement for the YP site.

Article Slug: remix-architecture Updated: 27 Jun 2026

Why Remix

The YP site is a public business directory. Search engines must crawl it, users must see content instantly, and the site must work without JavaScript. A client-side SPA fails all three requirements. Remix v2 on Cloudflare Workers solves this:

How it works on Cloudflare

Browser request
  -> Cloudflare Worker (worker.ts)
    -> Remix server bundle (build/server/index.js)
      -> Route matching
        -> loader() runs, queries D1
        -> React component renders to HTML stream
  <- Full HTML response (with hydration script)

The vite.config.ts uses the Remix Vite plugin which produces two outputs:

The wrangler.toml points main to worker.ts (which loads the Remix server bundle) and sets [assets] directory = "build/client".

Route structure

Routes live in app/routes/. The file name determines the URL:

Each route can export:

Loaders and D1

A loader receives the Cloudflare context and can query D1 directly:

export async function loader({ request, context }: LoaderFunctionArgs) {
  const db = context.cloudflare.env.DB;
  const url = new URL(request.url);
  const query = url.searchParams.get('q') || '';
  const results = await db.prepare('SELECT * FROM businesses WHERE name LIKE ?')
    .bind(`%${query}%`).all();
  return { results: results.results, query };
}

The component receives this data via useLoaderData():

export default function SearchPage() {
  const { results, query } = useLoaderData<typeof loader>();
  return <div>...</div>;
}

Progressive enhancement

Remix Form works like a regular HTML form — it submits without JavaScript. When JS loads, Remix intercepts the submission and does it via fetch for a smoother experience. This means:

Layout

The root layout lives in app/root.tsx. It provides the navigation bar, footer, global styles, and Remix plumbing (Meta, Links, Scripts, ScrollRestoration, Outlet). Individual routes render inside the Outlet.