Netlify adalah platform hosting populer dengan fitur-fitur unik seperti form handling built-in dan edge functions. Dengan free tier yang kompetitif, Netlify adalah alternatif solid untuk hosting Sitemas.
Mengapa Netlify?
| Fitur | Keterangan |
|---|---|
| Free Tier | 100GB bandwidth/bulan, 300 build minutes |
| Auto Deploy | Git-based deployment |
| Forms | Built-in form handling tanpa backend |
| Functions | Serverless functions (AWS Lambda) |
| Edge Functions | Deno-based edge computing |
| Split Testing | A/B testing built-in |
Persiapan
Sebelum mulai, pastikan:
- ✅ Akun GitHub/GitLab/Bitbucket
- ✅ Repository berisi proyek Sitemas
- ✅ Build lokal berhasil (
npm run build)
Deploy via Netlify CLI
Install Netlify CLI
Login ke Netlify
Browser akan terbuka untuk autentikasi.
Initialize Project
Pilih:
- Create & configure a new site
- Pilih team Anda
- Masukkan site name (atau biarkan random)
Deploy
Website live di https://sitename.netlify.app!
Deploy via Dashboard
Push ke GitHub
Import di Netlify
- Buka app.netlify.com
- Klik Add new site → Import an existing project
- Connect dengan Git provider Anda
- Pilih repository Sitemas
Configure Build Settings
| Setting | Value |
|---|---|
| Base directory | (kosongkan) |
| Build command | npm run build |
| Publish directory | dist |
Environment Variables
- Expand Advanced build settings
- Klik New variable
- Tambahkan variables yang diperlukan
Deploy Site
Klik Deploy site dan tunggu proses selesai.
Konfigurasi netlify.toml
Buat file netlify.toml di root untuk konfigurasi:
[build]
command = "npm run build"
publish = "dist"
[build.environment]
NODE_VERSION = "20"
# Headers untuk caching
[[headers]]
for = "/fonts/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/_astro/*"
[headers.values]
Cache-Control = "public, max-age=31536000, immutable"
[[headers]]
for = "/*"
[headers.values]
X-Frame-Options = "DENY"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "strict-origin-when-cross-origin"
# Redirects
[[redirects]]
from = "/old-url"
to = "/new-url"
status = 301
# SPA fallback (jika diperlukan)
[[redirects]]
from = "/*"
to = "/404"
status = 404 Environment Variables
Menambahkan di Dashboard
- Site settings → Environment variables
- Klik Add a variable
- Pilih scope: All deploys, Production, atau Deploy Previews
| Variable | Value | Scope |
|---|---|---|
PUBLIC_SITE_URL | https://yourdomain.com | Production |
PUBLIC_GA_MEASUREMENT_ID | G-XXXXXXXX | All |
Menggunakan di Code
const siteUrl = import.meta.env.PUBLIC_SITE_URL;
const gaId = import.meta.env.PUBLIC_GA_MEASUREMENT_ID; Deploy Contexts
Netlify mendukung berbagai deploy contexts:
| Context | Trigger | URL |
|---|---|---|
| Production | Push ke main/master | yourdomain.com |
| Deploy Preview | Pull Request | deploy-preview-123—sitename.netlify.app |
| Branch Deploy | Push ke branch lain | branchname—sitename.netlify.app |
Mengaktifkan Branch Deploys
- Site settings → Build & deploy → Branches and deploy contexts
- Pilih All atau Only production branch
Custom Domain
Tambah Domain
- Domain settings → Add custom domain
- Masukkan domain:
yourdomain.com
Konfigurasi DNS
Opsi 1: Netlify DNS (Recommended)
- Update nameservers ke Netlify
- Full control dan fastest propagation
Opsi 2: External DNS
# Apex domain
Type: A
Name: @
Value: 75.2.60.5
# www subdomain
Type: CNAME
Name: www
Value: sitename.netlify.app SSL Certificate
Netlify otomatis provision Let’s Encrypt SSL. Klik Verify DNS configuration untuk mempercepat.
Netlify Forms (Bonus)
Netlify menyediakan form handling tanpa backend:
<form name="contact" method="POST" data-netlify="true">
<input type="hidden" name="form-name" value="contact" />
<input type="text" name="name" required />
<input type="email" name="email" required />
<textarea name="message" required></textarea>
<button type="submit">Kirim</button>
</form> Submissions masuk ke Forms di dashboard.
100 submissions per bulan di free tier.
Build Plugins
Netlify memiliki plugin ecosystem. Yang berguna:
| Plugin | Fungsi |
|---|---|
| Lighthouse | Audit otomatis setiap deploy |
| Sitemap | Generate sitemap otomatis |
| Cache | Optimasi cache build |
Install via dashboard: Plugins → Browse
Monitoring
Deploy Logs
Setiap deploy punya log lengkap:
- Install dependencies
- Build process
- Deploy status
Analytics (Pro)
Netlify Analytics tersedia di Pro plan ($9/month per site).
Status Badges
Tambahkan badge ke README:
[](https://app.netlify.com/sites/SITENAME/deploys)
Troubleshooting
Build Gagal
| Error | Solusi |
|---|---|
Command failed | Cek build command dan Node version |
Deploy directory not found | Pastikan publish directory = dist |
| Timeout | Increase timeout atau optimize build |
404 Pages
Pastikan dist folder berisi semua halaman. Cek:
- Dynamic routes punya
getStaticPaths() - Tidak ada error saat build
Cache Issues
Clear cache dan redeploy:
- Deploys → Trigger deploy → Clear cache and deploy site
Perbandingan dengan Vercel
| Aspek | Vercel | Netlify |
|---|---|---|
| Astro support | Excellent | Excellent |
| Free tier bandwidth | 100GB | 100GB |
| Free build minutes | 6000/month | 300/month |
| Forms | ❌ | ✅ Built-in |
| Edge Functions | ✅ | ✅ |
| A/B Testing | Enterprise | ✅ Free |
Langkah Selanjutnya
Eksplorasi platform lain:
Deploy ke Cloudflare
Pelajari cara deploy ke Cloudflare Pages dengan edge performance.
Kesimpulan
Netlify adalah pilihan solid untuk hosting Sitemas dengan:
- Setup yang mudah
- Forms handling gratis
- Branch deploys untuk testing
- Plugins ecosystem
Pilih Netlify jika Anda butuh fitur forms atau A/B testing dalam free tier.