Why Netlify?
Netlify provides several compelling features:- Continuous Deployment: Automatic builds from Git
- Global CDN: Fast content delivery worldwide
- Form Handling: Built-in form processing
- Serverless Functions: Add backend functionality
- Deploy Previews: Test changes before going live
- Custom Domains: Free HTTPS with Let’s Encrypt
Prerequisites
Netlify Account
Create a free account at netlify.com
Deployment Methods
Method 1: Deploy via Netlify Dashboard (Recommended)
Import Repository
- Log in to Netlify
- Click Add new site → Import an existing project
- Connect to your Git provider and select your repository
Configure Build Settings
Set up your build configuration:
- Base directory: Leave empty (root)
- Build command:
pnpm run build - Publish directory:
dist - Node version: 18 or higher
Netlify auto-detects Astro projects, but it’s good to verify these settings.
Deploy Site
Click Deploy site and wait for the build to complete.Netlify will:
- Clone your repository
- Install dependencies
- Run the build command
- Deploy to their global CDN
- Provide a URL (e.g.,
random-name-123456.netlify.app)
Method 2: Deploy with Netlify CLI
For developers who prefer command-line workflows:Method 3: Deploy with netlify.toml
For version-controlled configuration, create anetlify.toml file:
Configuration Options
Build Settings
Optimize your build with these settings:Package Manager
Ensure Netlify uses pnpm by adding tonetlify.toml:
Post-Deployment Configuration
Custom Domain
Configure DNS
Point your domain to Netlify using one of these methods:Option A: Netlify DNS (Recommended)
- Use Netlify’s nameservers
- Automatic SSL certificate
- Managed DNS records
- Add a CNAME record pointing to your Netlify subdomain
- Add A record:
75.2.60.5
Enable HTTPS
Netlify automatically provisions a Let’s Encrypt certificate.Enable Force HTTPS in domain settings to redirect all HTTP traffic.
Environment Variables
Add environment variables for API keys and other configuration:- Go to Site settings → Environment variables
- Click Add a variable
- Enter key-value pairs
Automatic Deployments
Production Deployments
Netlify automatically deploys when you push to your production branch:Deploy Previews
Every pull request gets a deploy preview:- Create a feature branch
- Push changes and open a PR
- Netlify builds a preview and comments on the PR
- Test changes before merging
Deploy previews are available even on the free tier!
Branch Deploys
Deploy specific branches for staging:- Go to Site settings → Build & deploy → Deploy contexts
- Select branches to deploy
- Each branch gets its own subdomain
Advanced Features
Form Handling
Add forms to your portfolio without a backend:Redirects and Rewrites
Create SEO-friendly URLs with redirects:Custom Headers
Add security headers:Performance Optimization
Netlify provides several performance features:- Asset Optimization: Automatic image compression
- Pretty URLs: Clean URLs without
.htmlextensions - HTTP/2 Server Push: Faster asset loading
- Post Processing: Minification and bundling
- ✅ Bundle CSS
- ✅ Minify CSS
- ✅ Minify JS
- ✅ Compress images
Troubleshooting
Build fails: pnpm not found
Build fails: pnpm not found
Add pnpm installation to your build command:Or install via Netlify plugin:
Images not loading
Images not loading
Verify Sharp is in your dependencies:Check that images are in
public/ or imported correctly.404 on page refresh
404 on page refresh
This shouldn’t happen with Astro’s static output, but if it does, add to
netlify.toml:Build timeout
Build timeout
Free tier has a 15-minute build limit. Optimize by:
- Reducing image sizes
- Using cached dependencies
- Minimizing the number of pages
Monitoring and Analytics
Netlify Analytics
Enable server-side analytics (paid feature):- Go to your site dashboard
- Navigate to Analytics
- Enable Netlify Analytics
Deploy Notifications
Receive notifications about deployments:- Go to Site settings → Build & deploy → Deploy notifications
- Add notifications for:
- Deploy succeeded
- Deploy failed
- Deploy started
Rollback Deployments
Revert to a previous deployment:- Go to Deploys in your site dashboard
- Find the deployment you want to restore
- Click Publish deploy
Next Steps
Custom Domain
Set up a custom domain with HTTPS
Form Handling
Add contact forms without a backend
Functions
Add serverless functionality
Netlify CLI
Advanced CLI usage and local development