Build Process
Production Build
To create an optimized production build:astro build and generates static files in the dist/ directory.
Build Configuration
The build process is configured inastro.config.mjs with the following optimizations:
Output Mode
prerender: false on individual pages.
HTML Compression
CSS Optimization
- Stylesheets under 10KB are inlined to reduce render-blocking requests
- CSS is code-split for better loading performance
JavaScript Bundling
- esbuild used for fast minification
- Vendor chunks separated for better caching
- Dependencies cached independently from application code
Build Output
After runningnpm run build, the dist/ directory contains:
- Static HTML pages for all routes
- Optimized CSS and JavaScript bundles
- Sitemap (
sitemap-0.xml,sitemap-index.xml) - Assets in
_astro/directory with cache-busting hashes - Public assets (favicon, images, etc.)
Preview Production Build
Test the production build locally:dist/ directory to verify everything works as expected before deployment.
Vercel Deployment
The project is optimized for deployment on Vercel with the@astrojs/vercel adapter.
. (default)npm run build (auto-detected from package.json)dist (auto-detected)your-project.vercel.appVercel Configuration
The project includesvercel.json for additional configuration:
Security Headers
All routes include strict security headers:- Strict-Transport-Security: Force HTTPS (1 year, including subdomains)
- X-Frame-Options: DENY (prevent clickjacking)
- X-Content-Type-Options: nosniff (prevent MIME sniffing)
- X-XSS-Protection: Enable XSS filtering
- Referrer-Policy: strict-origin-when-cross-origin
- Permissions-Policy: Disable geolocation, microphone, camera, payment APIs
- Content-Security-Policy: Restrict resource loading (allows Umami analytics)
Cache Control
Optimized caching for static assets:- Astro assets (
_astro/*) cached for 1 year (immutable) - Favicon cached for 1 year
- Content-hashed filenames prevent stale caches
Redirects
Language-based redirects configured:- Root path (
/) redirects based onAccept-Languageheader - Spanish users →
/es/ - Others →
/en/(default)
Continuous Deployment
Vercel automatically deploys:- Production: Pushes to
mainbranch - Preview: Pull requests and other branches
- Unique preview URL
- Automatic SSL certificate
- Edge network distribution
- Performance analytics
Alternative Deployment Platforms
While optimized for Vercel, you can deploy to other platforms:Netlify
import netlify from '@astrojs/netlify';
export default defineConfig({
output: 'static',
adapter: netlify(),
// ... rest of config
});
Cloudflare Pages
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'static',
adapter: cloudflare(),
// ... rest of config
});
Static Hosting (Nginx, Apache, etc.)
For traditional static hosting:- Run
npm run build - Upload contents of
dist/to your web server - Configure server for:
- Trailing slashes (Astro uses
trailingSlash: "always") - MIME types for
.astroextensions (if needed) - Proper routing for SPA-like behavior
- Trailing slashes (Astro uses
Example Nginx Configuration
Troubleshooting
Build Fails
Check Node.js version:Deployment Issues
Vercel build timeout:- Check build logs for errors
- Verify dependencies are in
dependencies, notdevDependencies - Increase build timeout in Vercel project settings if needed
- Verify
trailingSlash: "always"is configured - Check that routes match expected URL structure
- Review redirects in
vercel.json
- Ensure
siteis configured inastro.config.mjs - Verify asset paths are relative or use
import - Check browser console for CORS or CSP errors
Performance Issues
Large bundle size:- Analyze with
npm run buildand check output - Consider lazy loading components
- Review imports for unused dependencies
- Check Vercel Analytics for performance insights
- Review Network tab in browser DevTools
- Verify caching headers are applied correctly
Next Steps
- Monitor deployments in Vercel dashboard
- Set up Vercel Analytics for performance monitoring
- Configure custom domains and SSL
- Review Code Quality for pre-deployment checks