Deploying a Frontend App

Intermediate · 15 min

How static hosting, environment variables, preview deploys, and deploy-on-push CI fit together to get a frontend app live and keep it live.

Before thisModule Bundlers & Build Tools

Lernoora · 15 min

Deploying a Frontend App

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by LernooraReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • A built frontend app is just static files — HTML, CSS, JS — so it can be served from a CDN rather than needing a traditional always-running server.
  • Platforms like Vercel, Netlify, GitHub Pages, and Cloudflare Pages differ mainly in build integration, edge functions, and pricing, not in the basic idea of hosting static output.
  • Environment variables let the same codebase behave differently per environment — pointing at a staging API versus production — without hardcoding secrets or URLs into the source.
  • A preview deploy builds and hosts a temporary, shareable version of a branch or pull request, so changes can be reviewed as a running app before they ever reach production.
  • Deploy-on-push CI means pushing to the right branch automatically triggers a build and deployment, removing the manual, error-prone step of shipping code by hand.

What “deploying a frontend app” actually means

Once a bundler like Vite has done its job — transpiled, bundled, tree-shaken your code — the output sitting in a dist folder is just files: an index.html, some .js and .css files, maybe images. There’s no server-side code to execute, no database connection to manage. This is the thing that makes frontend deployment categorically simpler than deploying a backend: you don’t need a machine running a process around the clock. You just need those files delivered to a browser quickly and reliably, which is a job a content delivery network (CDN) — a globally distributed network of servers that cache and serve files close to wherever the user physically is — is extremely good at.

This is why “static hosting” became its own category of platform, distinct from renting a traditional server. You hand over a folder of built files (or, more commonly today, point the platform at your Git repository and let it build the folder itself), and the platform takes care of serving it fast, worldwide, with HTTPS, without you managing any infrastructure.

Comparing the major platforms, conceptually

Vercel, Netlify, GitHub Pages, and Cloudflare Pages all do this same basic job — serve static output over a CDN — but differ in what they build around it.

GitHub Pages is the simplest and most limited: free static hosting tied directly to a GitHub repository, historically popular for documentation sites and simple project pages. It has no native concept of serverless functions or sophisticated build pipelines beyond a basic GitHub Actions workflow you wire up yourself.

Netlify popularized the modern “connect your Git repo, we build and deploy automatically” workflow for static sites, and added serverless functions so you could run small bits of backend logic (like handling a form submission) alongside static files, without standing up a separate server.

Vercel grew up alongside the framework Next.js and leans heavily into tight framework integration, edge functions, and fine-grained control over rendering strategies for frameworks that mix static and server-rendered content.

Cloudflare Pages builds on Cloudflare’s existing, famously large CDN network and edge-compute platform (Workers), appealing especially for very high traffic or latency-sensitive use cases, with a generous free tier.

None of these differences change the fundamental model. The practical choice usually comes down to which Git workflow and pricing model fits your project, not a difference in what’s architecturally possible.

Environment variables: one codebase, several environments

A real app usually needs to behave differently depending on where it’s running — pointing at a local backend during development, a staging API during QA, and the production API once live — without maintaining three separate copies of the code. Environment variables solve this: values like API_URL are read from the build or runtime environment rather than hardcoded, and each environment (local, staging, production) supplies its own values.

There’s a sharp line to understand here that trips up a lot of beginners: anything baked into a frontend build becomes visible to anyone who opens the browser’s dev tools, because it ships inside files the browser downloads and can read in full. An environment variable used in frontend code is not a place to put a true secret, like a database password — it’s a place for values that are safe to be public, such as a publishable API key or a base URL. True secrets stay server-side, in a backend or in serverless function configuration that never ships to the browser.

Preview deploys: reviewing a real, running app

A preview deploy takes this further: instead of only deploying main to production, the platform builds every branch or pull request into its own temporary, shareable URL. A designer, product manager, or reviewer can click that link and interact with the actual running change — not a screenshot, not a description, a real app — before it ever reaches production. This catches a category of bug that only shows up once code is actually built and deployed, which a developer’s local dev server can mask (different environment variables, different build optimizations, a path that only breaks in the production build).

Deploy-on-push: closing the loop

The last piece is removing the manual step entirely. In a deploy-on-push setup — the simplest real form of continuous integration/continuous deployment (CI/CD) a frontend team encounters — pushing to a given branch automatically triggers a build and, if it succeeds, a deployment. Push to main, production updates. Push to a feature branch, a preview deploy appears. There’s no person running a deploy command by hand, no “wait, did someone forget to ship this” — the pipeline from commit to live app is automatic, consistent, and exactly the same every time, which is the whole point: removing manual steps removes the mistakes that come with manual steps.

Check yourself

  1. 01Why can a frontend app typically be hosted as 'static files' instead of needing a full backend server?

    Once a bundler compiles the app down to HTML, CSS, and JavaScript, there's no server-side code left to execute for a basic app — the browser does all the work, so the files just need to be delivered, which a CDN can do without running any application logic at all.

  2. 02What's the core difference between the four major static hosting platforms at a conceptual level?

    They all serve static output over a CDN, but differ in how tightly they integrate with your Git provider for automatic builds, whether they offer serverless or edge functions alongside the static files, and their free-tier limits and pricing — not in the basic hosting model.

  3. 03Why shouldn't a secret API key be hardcoded directly into frontend source code, even as an environment variable baked in at build time?

    Anything bundled into the JavaScript that ships to a user's browser is visible to that user, since they can simply read the downloaded file — so only values that are safe to be public (like a publishable API key) belong in frontend environment variables, never a true secret.

  4. 04What problem does a preview deploy solve that a local 'it works on my machine' check doesn't?

    A preview deploy builds the branch exactly the way production will be built and hosts it at a real, shareable URL, so a reviewer, designer, or product manager can click through the actual change running in a real environment, catching build-specific or environment-specific issues a local dev server might hide.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark