Headless hosting workflows

Published

Updated

🔗

Headless backend systems with frontend heads.

In a headless project, a PHP backend serves content through an API and a separate JavaScript frontend renders it. fortrabbit hosts the PHP backend and can serve a statically built frontend next to it.

Headless setup

  • Backend: a PHP framework such as Laravel or Symfony, or a CMS such as Craft CMS, Kirby or Statamic, exposes content through a REST or GraphQL API.
  • Frontend: a JavaScript framework such as Vue, Nuxt, React or Next.js fetches the content and renders the pages.

Several frontends can share one backend. The price is two systems to build, deploy and keep in sync.

Hosting options

fortrabbit runs PHP. Node.js is available in the build commands, not as a server at runtime. That leaves two ways to host a headless project:

SetupBackendFrontend
Separatefortrabbit environmentFrontend host such as Netlify or Vercel
Togetherfortrabbit environmentBuilt statically during deployment, served from the same environment

Together, frontend and backend can share one repository, see monorepos. For other ways to map frontend and backend to apps and environments, see project organization.

Rendering modes

How the frontend renders decides what search engines see and where the frontend can run:

ModeHTML is createdRuns on fortrabbit
CSR, client-side renderingIn the browserYes
SSG, static site generationAt build timeYes
SSR, server-side renderingOn each request, by a Node.js serverNo
ISR, incremental static regenerationAt build time, then refreshed in the background by a Node.js serverNo

CSR suits apps behind a login, since search engines see little content. SSG serves fast static HTML, but content changes need a new build: trigger one from the CMS with a deploy hook.

Performance

A full static build queries every page of the backend at once. On a large site with many images, that creates a load peak on the backend during each deployment. GraphQL makes it easy to write queries that fetch far more than a page needs; check slow queries in the backend before blaming the server.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗