Netlify — Jamstack Hosting
Deploy static sites and SPAs with git-based CI/CD, form handling, identity, and edge functions
Skills taught: deployment.netlify, deployment.netlify-forms, deployment.netlify-functions, deployment.netlify-redirects, deployment.jamstack
Netlify — Vercel's closest competitor
Netlify and Vercel are very similar — both deploy frontend apps with git integration, preview deployments, custom domains, and serverless functions. Netlify pioneered many of these features (it invented the term 'Jamstack'). The key differences: Netlify has built-in form handling (collect form submissions without a backend), identity (authentication), and split testing out of the box. Vercel is better for Next.js and has a faster CDN. For non-Next.js static sites, either works equally well.
Deploying to Netlify
# Install Netlify CLI
npm install -g netlify-cli
# Login and deploy
netlify login
netlify init # link to GitHub repo and configure
netlify deploy # preview deploy
netlify deploy --prod # production deploy
# Manual deploy without CLI:
# netlify.com → New site → Import from Git → Select repo
# Configure: Build command, Publish directory
# Common framework settings:
# React/Vite: build: npm run build, publish: dist
# Next.js: build: npm run build, publish: .next (with @netlify/next plugin)
# Astro: build: npm run build, publish: dist
# Hugo: build: hugo, publish: public
netlify.toml — configuration
[build]
command = "npm run build"
publish = "dist"
# SPA routing — serve index.html for all routes
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
# 301 redirect old URLs
[[redirects]]
from = "/old-page"
to = "/new-page"
status = 301
# Proxy API calls (avoid CORS issues in development)
[[redirects]]
from = "/api/*"
to = "https://api.myapp.com/:splat"
status = 200
force = true
# HTTP security headers
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
Strict-Transport-Security = "max-age=31536000; includeSubDomains"
# Cache static assets long-term
[[headers]]
for = "/assets/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
# Environment-specific build settings
[context.production]
command = "npm run build:prod"
[context.branch-deploy]
command = "npm run build:staging"
Netlify's unique features
<!-- Add data-netlify='true' to any form — Netlify handles submissions -->
<form name="contact" method="POST" data-netlify="true">
<input type="hidden" name="form-name" value="contact" />
<label>Name: <input type="text" name="name" required /></label>
<label>Email: <input type="email" name="email" required /></label>
<label>Message: <textarea name="message"></textarea></label>
<button type="submit">Send</button>
</form>
<!-- That's it! Netlify:
- Intercepts form submissions
- Stores them in Netlify's form dashboard
- Sends email notifications
- Includes spam filtering
- Free up to 100 submissions/month
-->
// Functions go in /netlify/functions/ directory
// Called at: /.netlify/functions/hello
import type { Handler } from '@netlify/functions';
export const handler: Handler = async (event, context) => {
const name = event.queryStringParameters?.name ?? 'World';
return {
statusCode: 200,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: `Hello, ${name}!` }),
};
};
// Call from frontend:
fetch('/.netlify/functions/hello?name=Alice')
Tip: The _redirects file is the quickest way to configure SPA routing. Create a file named _redirects in your public/ folder (or wherever your publish directory is) with one line: /* /index.html 200. This tells Netlify to serve index.html for any path that doesn't match a real file — exactly what React Router and Vue Router need.
Frequently Asked Questions
Vercel vs Netlify — which should I choose?
Both are excellent — you can't go wrong with either. Prefer Vercel for: Next.js apps (Vercel made it), better edge performance, faster deployments. Prefer Netlify for: built-in form handling, split testing, identity management, or if you prefer their dashboard UX. For a static React app with no Next.js, flip a coin — both have generous free tiers and nearly identical DX.