From Development to Production: A Builder's Guide to Frontend Deployment Strategies
A practical guide to getting a frontend from your laptop to production. It compares managed platforms such as Vercel and Netlify, S3 behind CloudFront, and a multi-stage Docker image served by Nginx, with the SPA routing fix and cache headers for each. The Dockerfile, Nginx config and GitHub Actions workflow were linted, and the build stage was run against a Vite app.

Your app runs on localhost. Now it has to run for everyone, over HTTPS, without you typing commands each time. This guide is for frontend developers shipping their first real app, or moving off a manual upload. It compares three ways to deploy a built frontend: a managed platform, Amazon S3 behind CloudFront, and a Docker image served by Nginx. Each comes with the config you need, the single-page app routing fix, and cache rules.
This is part 28 of the Frontend & JavaScript Fundamentals series. The previous part, server-side rendering, matters here: a server-rendered app needs a running server, while a static build is just files.
Key takeaways
- Managed platforms build and deploy on every push and give each pull request a preview URL. Start there unless you have a reason not to.
- For S3 or Nginx, a single-page app needs a fallback to
index.html, andindex.htmlmust never be cached for long. - Hashed files such as
assets/index-DQT26LIo.jscan be cached for a year, because a new build gets a new name.
What deployment means for a frontend
Frontend deployment is the process of building your app into static files (or a server bundle) and serving them from a host that users can reach. For a Vite app, the Vite docs say npm run build writes the result to dist, and you can deploy that folder to any platform. They also warn that vite preview is for checking the build locally, not a production server.
Three questions decide the host:
- Is the build static files only, or does it need a server (SSR)?
- How much control do you need over headers, regions and costs?
- Who maintains the setup when something breaks?
Option 1: A managed platform (Vercel or Netlify)
You connect a Git repository, and the platform builds and deploys on every push. The Vite guide notes that Vercel detects a Vite project and applies the right settings.
What you get:
- Preview deployments. Vercel creates a preview for every push to a non-production branch and every pull request. Netlify builds a Deploy Preview for each pull request, at a URL such as
deploy-preview-42--mysitename.netlify.app. - Production on merge. Vercel deploys to production when you push to the production branch, often
main.
For a single-page app on Netlify, add one rewrite so deep links such as /dashboard load your app. The Netlify docs give this rule for netlify.toml:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
The trade-off is control. You work within each platform's build limits, features and pricing, so read the current pricing page before you plan for heavy traffic.
Option 2: S3 behind CloudFront
Here you assemble the parts yourself. Amazon S3 stores the files, and CloudFront, a content delivery network (CDN), serves them from edge locations.
Keep the bucket private. CloudFront's docs recommend origin access control (OAC), which lets only your distribution read the bucket. Note one catch from the same page: OAC works with a regular bucket, not one set up as an S3 website endpoint.
Then deploy in two passes, so each file gets the right cache header:
npm run build
# 1. Hashed assets: safe to cache for a year
aws s3 sync dist/assets s3://my-app-bucket/assets \
--cache-control "public, max-age=31536000, immutable"
# 2. Everything else, including index.html: always revalidate
aws s3 sync dist s3://my-app-bucket --delete \
--exclude "assets/*" --cache-control "no-cache"
# 3. Drop the old index.html from CloudFront's edge caches
aws cloudfront create-invalidation \
--distribution-id "$CF_DISTRIBUTION_ID" --paths "/index.html"
Why this order? New assets go up first, so the new index.html never points to files that aren't there yet. The --delete flag skips files matched by --exclude, as the s3 sync reference notes, so old assets stay for users who still have the previous page open.
Why not just invalidate /*? CloudFront's invalidation docs recommend versioned file names over invalidation when files change often. Versioned names work even in browser and proxy caches, and they need no invalidation, so there is no invalidation charge. Your bundler already adds the hashes.
# Avoid: cache everything the same way, then flush the whole CDN
aws s3 sync dist s3://my-app-bucket --delete
aws cloudfront create-invalidation --distribution-id "$CF_DISTRIBUTION_ID" --paths "/*"
Fix deep links on CloudFront
If someone opens /dashboard directly, there is no dashboard file in the bucket, so the request fails. CloudFront's custom error responses can replace the error with another page and change the response code. Map 403 and 404 to /index.html with a 200 code, and your router takes over in the browser. Note the side effect: a missing file under /assets/ now also returns index.html with a 200, unlike the Nginx setup below.
Option 3: A Docker image with Nginx
A container fits when your company already runs containers, for example on Kubernetes, or when you need the same image in every environment. A multi-stage build keeps the image small: the Docker docs describe using several FROM lines and copying only the built output into the final stage.
# Stage 1: build the app
FROM node:24-alpine AS build
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .
RUN npm run build
# Stage 2: serve the files with Nginx
FROM nginx:stable-alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 80
The final image holds Nginx and your dist files, with no Node.js and no node_modules. The official nginx image page shows the same pattern of copying static files into /usr/share/nginx/html. The Node.js releases page lists 22, 24 and 26 as LTS lines and says production apps should only use LTS releases. Pick one and update it when it nears end of life.
Add a .dockerignore, so COPY . . doesn't send your local node_modules or secrets into the build:
node_modules
dist
.git
.env*
Now the Nginx config. It does two jobs: the SPA fallback and the cache headers.
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
# Hashed files never change, so browsers may keep them for a year
location /assets/ {
add_header Cache-Control "public, max-age=31536000, immutable";
try_files $uri =404;
}
# Everything else falls back to index.html, which must always be revalidated
location / {
add_header Cache-Control "no-cache";
try_files $uri $uri/ /index.html;
}
}
try_files checks each file in order. If none exists, nginx's docs say it makes an internal redirect to the last parameter, here /index.html. Missing files under /assets/ get a real 404 instead, so a broken script link fails loudly rather than returning HTML.
add_header is not inherited the way you might expect
nginx's docs say a block inherits add_header lines from the level above only if it defines none of its own. If you add a security header at the server level, repeat it inside each location that has its own add_header.
If you serve an SSR app, this setup doesn't apply. Nginx then sits in front of a Node.js server as a proxy, and the Next.js streaming guide notes that Nginx buffers responses by default, which delays streamed HTML.
Automate the build with GitHub Actions
Deploying from your own laptop ties every release to you. A workflow builds the same way each time. This one builds the image and pushes it to Docker Hub on every push to main:
name: Build and push image
on:
push:
branches: [main]
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v4
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push
uses: docker/build-push-action@v7
with:
push: true
tags: |
${{ vars.DOCKERHUB_USERNAME }}/my-frontend:latest
${{ vars.DOCKERHUB_USERNAME }}/my-frontend:${{ github.sha }}
The action versions and the DOCKERHUB_USERNAME variable plus DOCKERHUB_TOKEN secret follow Docker's GitHub Actions docs. No checkout step is needed, because the build action uses the Git context by default. The second tag, the commit SHA, lets you roll back to an exact build; latest alone can't tell you what is running.
The Dockerfile passed hadolint, the workflow passed actionlint, and the Nginx config parsed cleanly with crossplane, on 2026-10-29. The build stage commands (npm ci, then npm run build) ran against a Vite 8.3.5 app on Node.js 24.22.2, the line the Dockerfile uses, and wrote dist/index.html and dist/assets/index-DQT26LIo.js. Docker, Nginx and the AWS commands were not run for this guide, so test the image and the upload script before you ship them.
Fixed in this version
The earlier Dockerfile used node:18-alpine, a Node.js line that reached end of life in 2025. Its S3 comment said "set public read" though nothing did, and the workflow used old action versions with only a latest tag.
Which option to choose
| Option | What it does | Trade-off | When to use |
|---|---|---|---|
| Vercel or Netlify | Builds on push, previews per pull request, can run SSR | Less control; platform limits and pricing | Most new apps, side projects, small teams |
| S3 + CloudFront | Serves static files from a private bucket via a CDN | You own cache headers, routing and IAM | Static apps on AWS that need control over cost and headers |
| Docker + Nginx | Packs the app and its server config in one image | You run and patch the container platform | Teams already on Kubernetes or another container platform |
As a rule of thumb, start with a managed platform. Move when a real requirement, such as a region, a compliance rule or a cost limit, pushes you out.
Next in the series, micro frontends looks at what happens when several teams deploy parts of one frontend on their own schedules.
Frequently asked questions
Why does my React app show 404 when I refresh a page?
The host looks for a file that matches the path, such as /dashboard, and finds none. Your router only exists inside index.html. Add a fallback to index.html: a rewrite on Netlify, try_files on Nginx, or a custom error response on CloudFront.
Should I cache index.html?
Not for long. Use no-cache, so browsers check for a new version on every visit. Cache the hashed files in assets/ for a year instead, because their names change whenever their content does.
Is Docker overkill for a static frontend?
Often, yes. A static build needs only a file host and a CDN. Docker earns its place when your organization already deploys everything as containers, or when the frontend ships alongside services in the same cluster.
Can I put a Next.js SSR app on S3?
Not the server-rendered parts. S3 only serves files, so it can host a static export, but SSR needs a running server. The Next.js streaming guide lists a Node.js server and a Docker container as supported targets, and static export as unsupported for streaming.
Where should API keys go in a frontend deployment?
Not in the bundle. Anything in client JavaScript is public. Keep secrets on a server or in serverless functions, and store CI credentials as encrypted secrets, as the workflow above does with DOCKERHUB_TOKEN.
Sources
Verified against the sources below on October 29, 2026. Products and docs change often: check the linked sources if something looks different.
- Vite: Deploying a static site
- Vercel: Environments
- Netlify: Deploy Previews
- Netlify: Rewrites and proxies
- AWS CLI: s3 sync
- Amazon CloudFront: Restrict access to an Amazon S3 origin
- Amazon CloudFront: Generate custom error responses
- Amazon CloudFront: Invalidate files
- Node.js: Previous releases
- Next.js: Streaming (platform support)
- Docker: Multi-stage builds
- Docker Official Image: nginx
- nginx: try_files
- nginx: add_header
- Docker: GitHub Actions
All 30 parts in this series
- Part 01Overcoming the Daunting Start: A Strategic Roadmap for New Frontend Developers
- Part 02Beyond the Tags: Mastering HTML Architecture for Product-Based Roles
- Part 03From Selectors to BEM: CSS Concepts You Must Know for Professional Projects
- Part 04Mastering the Primitives: A Builder's Guide to JavaScript Data Types and Functions
- Part 05Demystifying Scope and Closure: Key Concepts for Writing Robust JavaScript
- Part 06Beyond Frameworks: Practical DOM Manipulation Techniques for High-Performance UIs
- Part 07From Prototypes to ES6 Classes: Understanding JavaScript's Object-Oriented Nature
- Part 08Architecting Scalable JavaScript: OOP Principles & Design Patterns
- Part 09Mastering the Metal: Essential Web APIs & Browser Internals for Frontend Engineers
- Part 10Understanding the JavaScript Runtime: Event Loop, Call Stack, and Task Queue Explained
- Part 11Mastering Asynchronous Operations with JavaScript Promises: A Builder's Guide
- Part 12Modern Async Patterns: Making Asynchronous Code Readable with Async/Await and Generators
- Part 13Inside the V8 Engine: A Deep Dive into JavaScript Execution
- Part 14Demystifying CORS, HTTP, and Security: A Builder’s Guide
- Part 15REST vs. GraphQL: A Frontend Engineer’s Reality Check
- Part 16Secure Frontend Auth: The Definitive Guide to JWTs, Cookies, and Storage Strategies
- Part 17Why TypeScript Matters: Adding Type Safety to Your JavaScript Projects
- Part 18Getting Started with React: Deconstructing JSX and Component Architecture
- Part 19React Architecture: Mastering State and Props in Class vs. Functional Components
- Part 20Mastering React Hooks: From useState to Building a Production-Ready Custom Hook
- Part 21React State Management: Context API vs. Redux & Building a Theme Switcher
- Part 22React Architecture: Advanced Navigation and Data Flow Patterns
- Part 23Automated Testing in React: Unit Testing with Jest and React Testing Library
- Part 24Mastering Chrome DevTools: Debugging Techniques That Save Hours of Development Time
- Part 25Automating Code Quality: The Modern Stack with ESLint, Prettier, and Husky
- Part 26Demystifying the Build Pipeline: A Deep Dive into Webpack and Babel Configuration
- Part 27Improving Performance with Server-Side Rendering: Concepts and Implementation
- Part 28From Development to Production: A Builder's Guide to Frontend Deployment Strategies
- Part 29Introduction to Micro Frontends: Building Scalable Architectures
- Part 30The Frontend Architecture: From Junior Developer to Tech Lead
AI Automation Engineer & Salesforce Developer
Salesforce developer since June 2018. I build AI agents, n8n workflows and Salesforce integrations, and write up what holds up in real use.



Comments
Loading comments...