Performa website adalah faktor ranking Google dan menentukan user experience. Sitemas di-design untuk performa optimal out-of-the-box. Artikel ini menjelaskan optimasi yang sudah dilakukan dan cara mempertahankannya.
Core Web Vitals
Google menggunakan 3 metrik utama untuk mengukur user experience:
| Metrik | Deskripsi | Target |
|---|---|---|
| LCP (Largest Contentful Paint) | Waktu render elemen terbesar | < 2.5s |
| FID (First Input Delay) | Response time input pertama | < 100ms |
| CLS (Cumulative Layout Shift) | Stabilitas visual | < 0.1 |
Mulai Maret 2024, Google mengganti FID dengan INP (Interaction to Next Paint). Sitemas sudah dioptimasi untuk keduanya.
Optimasi LCP
LCP mengukur berapa lama sampai konten utama terlihat.
Apa yang Sudah Dilakukan Sitemas
- Static Site Generation — Tidak ada server-side rendering
- Font Preloading — Critical fonts di-preload
- Image Optimization — Astro Image component dengan lazy loading
- Minimal JavaScript — Hampir semua rendering di server
Tips Mempertahankan LCP Bagus
1. Optimize Hero Images
# Gunakan heroImage yang sudah dioptimasi
heroImage: ./hero.webp # WebP lebih kecil dari PNG/JPG
Rekomendasi ukuran:
- Max width: 1920px
- Format: WebP atau AVIF
- Quality: 80-85%
2. Preload Critical Images
<link
rel="preload"
href="/images/hero.webp"
as="image"
/> 3. Jangan Block Rendering
<!-- ❌ Render blocking -->
<script src="analytics.js"></script>
<!-- ✅ Non-blocking -->
<script defer src="analytics.js"></script>
<script async src="analytics.js"></script>
Optimasi FID/INP
FID dan INP mengukur responsivitas interaksi.
Apa yang Sudah Dilakukan Sitemas
- Minimal Client JavaScript — Hampir semua di server
- Code Splitting — Per-page bundles
- Async Scripts — Third-party scripts non-blocking
- Event Delegation — Efficient event handling
Tips Mempertahankan FID/INP Bagus
1. Lazy Load Non-Critical JS
// Jangan load langsung
import heavyLibrary from 'heavy-library';
// Load saat dibutuhkan
const button = document.querySelector('.load-feature');
button.addEventListener('click', async () => {
const { heavyFunction } = await import('heavy-library');
heavyFunction();
}); 2. Debounce Heavy Operations
function debounce(fn, delay) {
let timeout;
return (...args) => {
clearTimeout(timeout);
timeout = setTimeout(() => fn(...args), delay);
};
}
window.addEventListener('scroll', debounce(() => {
// Heavy operation
}, 100)); 3. Use requestIdleCallback
// Run non-critical task when browser is idle
requestIdleCallback(() => {
// Analytics, prefetch, etc.
}, { timeout: 2000 }); Optimasi CLS
CLS mengukur stabilitas layout — apakah elemen “melompat”.
Apa yang Sudah Dilakukan Sitemas
- Reserved Space untuk Ads — Container dengan min-height
- Font Display Swap — Tidak ada invisible text
- Image Dimensions — Width/height attributes
- Skeleton Loading — Placeholder saat loading
Tips Mempertahankan CLS Bagus
1. Selalu Set Dimensi Image
<!-- ✅ Bagus -->
<img src="photo.jpg" width="800" height="600" alt="..." />
<!-- ❌ Menyebabkan layout shift -->
<img src="photo.jpg" alt="..." />
Dengan Astro Image component, ini otomatis:
<Image src={myImage} alt="..." />
2. Reserve Space untuk Dynamic Content
.ad-container {
min-height: 250px; /* Reserve space */
contain: layout; /* Isolate layout */
}
.lazy-component {
min-height: 300px;
aspect-ratio: 16 / 9;
} 3. Avoid Injecting Content Above Existing
// ❌ Menyebabkan shift
element.insertBefore(newContent, existingContent);
// ✅ Tidak menyebabkan shift (di bawah viewport)
element.appendChild(newContent);
Optimasi Asset
Image Optimization
Sitemas menggunakan Astro Image untuk optimasi otomatis:
---
import { Image } from 'astro:assets';
import heroImage from './hero.jpg';
---
<Image
src={heroImage}
alt="Hero image"
width={1200}
quality={85}
format="webp"
loading="lazy"
/> Font Optimization
Sitemas self-host fonts untuk performa:
@font-face {
font-family: 'Google Sans';
src: url('/fonts/GoogleSans-Regular.woff2') format('woff2');
font-weight: 400;
font-display: swap; /* Prevent FOIT */
} Preload critical fonts:
<link
rel="preload"
href="/fonts/GoogleSans-Regular.woff2"
as="font"
type="font/woff2"
crossorigin
/>
JavaScript Bundle Size
Sitemas menjaga bundle size minimal:
| Bundle | Size (gzip) |
|---|---|
| Main | ~15KB |
| Per-page | ~2-5KB |
| Total (typical page) | ~20KB |
Tips menjaga bundle kecil:
- Avoid large libraries
- Tree-shake imports
- Use native APIs when possible
Caching Strategy
Static Assets
Assets dengan hash di filename (immutable):
# /_astro/* files
Cache-Control: public, max-age=31536000, immutable
# /fonts/* files
Cache-Control: public, max-age=31536000, immutable HTML Pages
HTML bisa di-cache dengan revalidation:
Cache-Control: public, max-age=0, must-revalidate Monitoring Performa
PageSpeed Insights
- Buka PageSpeed Insights
- Masukkan URL
- Review score dan recommendations
Target scores:
- Performance: 90+
- Accessibility: 90+
- Best Practices: 90+
- SEO: 90+
Lighthouse CI
Automate testing dengan Lighthouse CI:
module.exports = {
ci: {
collect: {
url: ['http://localhost:4321/'],
startServerCommand: 'npm run preview',
},
assert: {
assertions: {
'categories:performance': ['error', { minScore: 0.9 }],
'categories:accessibility': ['error', { minScore: 0.9 }],
'categories:seo': ['error', { minScore: 0.9 }],
},
},
},
}; Real User Monitoring
Untuk data real users, gunakan:
- Vercel Analytics — Built-in jika deploy di Vercel
- Cloudflare Web Analytics — Gratis, privacy-friendly
- Google Analytics — Web Vitals report
Checklist Performa
Sebelum deploy ke production:
- Semua images menggunakan Astro Image component
- Hero images di-preload
- Fonts di-self-host dan preload
- Third-party scripts async/defer
- Ads container punya min-height
- Tidak ada render-blocking resources
- PageSpeed score 90+ di semua kategori
- CLS < 0.1
- LCP < 2.5s
Troubleshooting
LCP Lambat
| Penyebab | Solusi |
|---|---|
| Image besar | Compress dan resize |
| Font loading | Preload critical fonts |
| Server lambat | Gunakan CDN |
| Render blocking JS | Tambahkan defer/async |
CLS Tinggi
| Penyebab | Solusi |
|---|---|
| Image tanpa dimensi | Tambahkan width/height |
| Font swap | Gunakan font-display: swap |
| Ads tanpa placeholder | Reserve space dengan min-height |
| Dynamic content | Load di bawah fold |
FID/INP Lambat
| Penyebab | Solusi |
|---|---|
| Heavy JS execution | Code split, lazy load |
| Third-party scripts | Load async, delay |
| Complex event handlers | Debounce, use RAF |
Langkah Selanjutnya
Dokumentasi sudah hampir lengkap! Lihat troubleshooting:
Troubleshooting
Solusi untuk masalah umum saat menggunakan Sitemas.
Kesimpulan
Performa adalah feature. Sitemas memberikan fondasi performa yang solid:
- Static generation — Tidak ada SSR latency
- Optimized assets — Images, fonts, JS minimal
- Modern CSS — No heavy CSS frameworks
- Edge-ready — Deploy ke CDN global
Tugas Anda adalah menjaga performa saat menambahkan konten:
- Optimize images sebelum upload
- Limit third-party scripts
- Test dengan PageSpeed secara berkala
Dengan pendekatan ini, website Sitemas Anda akan tetap cepat seiring pertumbuhan konten.