This document outlines all performance optimizations implemented in the SAVIGN website and provides guidelines for maintaining optimal performance.
- First Contentful Paint (FCP): < 1.5s
- Largest Contentful Paint (LCP): < 2.5s
- Time to Interactive (TTI): < 3.5s
- Cumulative Layout Shift (CLS): < 0.1
- First Input Delay (FID): < 100ms
- Total Page Weight: < 500KB (initial load)
- HTML: < 50KB
- CSS: < 50KB (minified)
- JavaScript: < 100KB (minified)
- Images: < 200KB per hero image, < 100KB per content image
<picture>
<source srcset="image.webp" type="image/webp">
<source srcset="image.jpg" type="image/jpeg">
<img src="image.jpg" alt="Description" loading="lazy">
</picture>Benefits:
- WebP provides 25-35% better compression than JPEG
- Fallback ensures compatibility with all browsers
- Lazy loading reduces initial page weight
<picture>
<source srcset="image-small.webp 400w,
image-medium.webp 800w,
image-large.webp 1200w"
type="image/webp"
sizes="(max-width: 768px) 100vw, 50vw">
<img src="image-medium.jpg" alt="Description" loading="lazy">
</picture>Benefits:
- Serves appropriately sized images for each device
- Reduces bandwidth usage on mobile devices
- Improves load times
- All below-the-fold images use
loading="lazy" - Above-the-fold images load immediately
- Reduces initial page weight by 40-60%
Implementation:
See assets/images/README.md for detailed guidelines
Critical above-the-fold CSS is inlined in <head>:
- Header/navigation styles
- Hero section styles
- Essential reset and variables
- Critical responsive breakpoints
Benefits:
- Eliminates render-blocking CSS requests
- Faster First Contentful Paint
- Improved perceived performance
Non-critical CSS loads asynchronously:
<link rel="preload" href="./css/components.css" as="style"
onload="this.onload=null;this.rel='stylesheet'">Benefits:
- Doesn't block page rendering
- Progressive enhancement
- Faster Time to Interactive
Production CSS is minified:
- Removes comments and whitespace
- Reduces file size by 30-40%
- Faster download and parse times
Build Command:
./build-css.shAll sizing uses relative units:
remfor consistent scalingemfor component-relative sizingvw/vhfor viewport-relative sizingclamp()for fluid typography
Benefits:
- Better responsive behavior
- Accessibility (respects user font size preferences)
- Smaller CSS file size
Implementation:
See css/README.md for detailed guidelines
All scripts use defer attribute:
<script src="./js/main.js" defer></script>Benefits:
- Scripts don't block HTML parsing
- Execute after DOM is ready
- Maintains execution order
- Faster page load
Resize and scroll events are optimized:
Debouncing (resize events):
const handleResize = debounce(() => {
// Runs 150ms after resize stops
}, 150);Throttling (scroll events):
const handleScroll = throttle(() => {
// Runs at most once per 100ms
}, 100);Benefits:
- Reduces function calls by 90%+
- Prevents performance bottlenecks
- Smoother scrolling and resizing
Single event listener on parent instead of multiple listeners:
// One listener handles all menu links
menuOverlay.addEventListener('click', (e) => {
if (e.target.classList.contains('menu-link')) {
close();
}
});Benefits:
- Fewer event listeners = less memory
- Better performance
- Works with dynamic content
Scroll animations use Intersection Observer instead of scroll events:
const observer = new IntersectionObserver(callback, options);
observer.observe(element);Benefits:
- More efficient than scroll listeners
- Automatic viewport calculations
- Better battery life on mobile
Production JavaScript is minified:
- Removes comments and whitespace
- Shortens variable names
- Reduces file size by 40-50%
Build Command:
./build-js.shImplementation:
See js/README.md for detailed guidelines
All animations use only transform and opacity:
.element {
transition: transform 0.3s ease, opacity 0.3s ease;
}
.element:hover {
transform: scale(1.02);
opacity: 0.9;
}Benefits:
- GPU acceleration
- 60fps animations
- No layout thrashing
Respects user preferences:
@media (prefers-reduced-motion: reduce) {
* {
animation: none !important;
transition: none !important;
}
}Benefits:
- Accessibility compliance
- Better experience for users with motion sensitivity
- Improved performance on low-end devices
<link rel="preload" href="./css/main.css" as="style">
<link rel="dns-prefetch" href="https://fonts.googleapis.com">Benefits:
- Faster resource loading
- Reduced latency
- Better perceived performance
Enable gzip/brotli compression on server:
# .htaccess (Apache)
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/javascript
</IfModule>
Benefits:
- 70-80% file size reduction
- Faster downloads
- Lower bandwidth costs
Use unminified files for easier debugging:
# No build needed, use source files directlyBuild optimized files for deployment:
# Build everything
./build.sh
# Or build individually
./build-css.sh
./build-js.sh- Run production build
- Use
index.prod.htmlor updateindex.htmlto use minified files - Deploy all files including
css/dist/andjs/dist/ - Enable compression on server
- Set appropriate cache headers
# Install
npm install -g lighthouse
# Run audit
lighthouse http://localhost:8000 --viewTargets:
- Performance: > 90
- Accessibility: > 90
- Best Practices: > 90
- SEO: > 90
- Visit https://www.webpagetest.org/
- Test from multiple locations
- Test on different connection speeds
- Analyze waterfall charts
Performance Tab:
- Open DevTools (F12)
- Go to Performance tab
- Click Record
- Interact with page
- Stop recording
- Analyze timeline
Coverage Tab:
- Open DevTools (F12)
- Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows)
- Type "Coverage"
- Click "Start instrumenting coverage"
- Reload page
- Identify unused CSS/JS
Network Tab:
- Open DevTools (F12)
- Go to Network tab
- Reload page
- Check file sizes and load times
- Test with throttling (Slow 3G, Fast 3G)
- Run Lighthouse audit (score > 90)
- Test on slow 3G connection
- Test on low-end mobile device
- Verify all images are optimized
- Verify CSS is minified
- Verify JavaScript is minified
- Check for console errors
- Test all interactive features
- Verify lazy loading works
- Check Core Web Vitals
- Run Lighthouse on live site
- Test from multiple locations
- Monitor real user metrics
- Check server compression
- Verify cache headers
- Test on various devices/browsers
Consider implementing:
- Google Analytics 4 (Web Vitals)
- Cloudflare Web Analytics
- Vercel Analytics
- Custom performance tracking
Set up automated testing:
- Lighthouse CI
- WebPageTest API
- Pingdom
- UptimeRobot
Push critical resources before browser requests them
Cache assets for offline access and faster repeat visits
Split JavaScript into smaller chunks loaded on demand
Remove unused code from JavaScript bundles
Use CDN with automatic optimization (Cloudinary, Imgix)
- Use variable fonts
- Subset fonts to include only needed characters
- Use font-display: swap
<link rel="preconnect" href="https://fonts.googleapis.com">Set up performance budgets in build process:
{
"budgets": [
{
"resourceSizes": [
{ "resourceType": "script", "budget": 100 },
{ "resourceType": "stylesheet", "budget": 50 },
{ "resourceType": "image", "budget": 200 }
]
}
]
}- Fail builds that exceed budget
- Alert team when approaching limits
- Regular performance reviews
✅ Optimize images before adding to site ✅ Use lazy loading for below-fold content ✅ Minify CSS and JavaScript for production ✅ Use relative units for responsive design ✅ Debounce/throttle event handlers ✅ Use GPU-accelerated animations ✅ Test on real devices ✅ Monitor performance metrics
❌ Don't add images without optimization ❌ Don't use large JavaScript libraries unnecessarily ❌ Don't animate layout properties (width, height, top, left) ❌ Don't use inline styles (except critical CSS) ❌ Don't ignore console warnings ❌ Don't skip performance testing ❌ Don't deploy without minification
For questions or issues related to performance optimization, please refer to:
assets/images/README.md- Image optimizationcss/README.md- CSS optimizationjs/README.md- JavaScript optimization