perf(smoothness): eliminate scroll lag via responsive WebP hero, native 120Hz smooth scroll, intersection observer navbar, and removing 50+ backdrop-filter blur bottlenecks

This commit is contained in:
2026-11-05 17:15:36 +05:30
parent 44cb60ecfe
commit d13008b334
11 changed files with 73 additions and 174 deletions
+21 -12
View File
@@ -268,21 +268,30 @@ export function HeroSection({
// -------------------------------------------------------------
return (
<section className="relative min-h-[92vh] sm:min-h-screen flex items-center overflow-hidden bg-black pt-20 sm:pt-24 pb-14 sm:pb-20">
{/* 1. Background Image with Left Dark Gradient Overlay */}
<div className="absolute inset-0 z-0">
<img
src="/management/pages/home/Image_homepage.jpg"
alt="CRE AI Photo Magic"
className="w-full h-full object-cover object-[75%_center] sm:object-right-top select-none pointer-events-none"
loading="eager"
decoding="async"
/>
{/* 1. Background Image with Responsive Ultra-Fast Loading */}
<div className="absolute inset-0 z-0 overflow-hidden">
<picture>
<source media="(max-width: 768px)" srcSet="/management/pages/home/hero_mobile.webp" type="image/webp" />
<source media="(max-width: 768px)" srcSet="/management/pages/home/hero_mobile.jpg" type="image/jpeg" />
<source srcSet="/management/pages/home/hero_desktop.webp" type="image/webp" />
<img
src="/management/pages/home/hero_desktop.jpg"
alt="CRE AI Photo Magic"
className="w-full h-full object-cover object-[75%_center] sm:object-right-top select-none pointer-events-none"
loading="eager"
fetchPriority="high"
decoding="async"
/>
</picture>
{/* Dark Gradient Overlay for Maximum Text Readability */}
<div className="absolute inset-0 bg-gradient-to-r from-black/95 via-black/75 to-black/30 sm:via-black/55 sm:to-transparent" />
<div className="absolute inset-0 bg-gradient-to-r from-black/95 via-black/75 to-black/30 sm:via-black/55 sm:to-transparent pointer-events-none" />
{/* Smooth Bottom Blend to Section Below */}
<div className="absolute inset-x-0 bottom-0 h-28 bg-gradient-to-t from-[#FAF8F5] via-[#FAF8F5]/70 to-transparent pointer-events-none" />
</div>
{/* Zero-Overhead Scroll Sentinel for Navbar Transformation */}
<div id="hero-sentinel" className="absolute bottom-28 left-0 w-full h-1 pointer-events-none opacity-0" aria-hidden="true" />
{/* 2. Left-Aligned Content Container */}
<div className="relative z-10 max-w-[1640px] w-full mx-auto px-4 sm:px-8 lg:px-14 flex flex-col justify-center min-h-[90vh] sm:min-h-[92vh]">
<div className="max-w-2xl sm:max-w-3xl">
@@ -318,8 +327,8 @@ export function HeroSection({
</a>
</div>
{/* Glass Metrics Pill Capsule */}
<div className="mt-12 sm:mt-16 w-full max-w-2xl sm:max-w-3xl rounded-3xl sm:rounded-full bg-white/[0.06] backdrop-blur-xl border border-white/20 p-4 sm:py-4 sm:px-8 grid grid-cols-2 sm:grid-cols-4 gap-4 sm:gap-6 shadow-2xl">
{/* Glass Metrics Pill Capsule (0% CPU, Hardware-Accelerated) */}
<div className="mt-12 sm:mt-16 w-full max-w-2xl sm:max-w-3xl rounded-3xl sm:rounded-full bg-slate-950/75 border border-white/15 p-4 sm:py-4 sm:px-8 grid grid-cols-2 sm:grid-cols-4 gap-4 sm:gap-6 shadow-2xl">
{/* Metric 1 */}
<div className="flex flex-col text-left">
<span className="text-xl sm:text-2xl font-display font-black tracking-tight text-blue-400">
@@ -188,7 +188,7 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
{item.mediaType === 'comparison' ? (
<div
style={{ borderRadius: '28px' }}
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)] bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
>
{/* GPU-Composited Shadow Elevation Layer */}
<div
@@ -203,7 +203,7 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
{/* Dedicated Tool Link Pill on top right so sliding never accidentally navigates */}
<Link
href={`/tools/${item.slug}`}
className="absolute top-3 right-3 z-30 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20 hover:bg-blue-600 transition-colors shadow-sm cursor-pointer"
className="absolute top-3 right-3 z-30 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/90 text-white border border-white/20 hover:bg-blue-600 transition-colors shadow-sm cursor-pointer"
aria-label={`Open ${item.title}`}
>
<span>TRY TOOL</span>
@@ -214,7 +214,7 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
<Link
href={`/tools/${item.slug}`}
style={{ borderRadius: '28px' }}
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)] bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm cursor-pointer"
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm cursor-pointer"
>
{/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */}
<div
@@ -453,7 +453,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
return (
<div
style={{ borderRadius: '28px' }}
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)]"
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
>
<video
ref={videoRef}
@@ -491,7 +491,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
touchAction: 'pan-y',
borderRadius: '28px',
}}
className="relative w-full h-full select-none overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)] cursor-ew-resize"
className="relative w-full h-full select-none overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate cursor-ew-resize"
>
{/* Layer 1: AFTER Image (Base layer, fixed scale & position, 0% zoom) */}
<img
@@ -505,7 +505,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
{/* Layer 2: BEFORE Image (Clipped container-sized layer - 100% exact alignment with slider divider on phone & desktop) */}
<div
ref={clipLayerRef}
className="absolute inset-0 overflow-hidden rounded-[28px] sm:rounded-[36px] isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)] pointer-events-none"
className="absolute inset-0 overflow-hidden rounded-[28px] sm:rounded-[36px] isolate pointer-events-none"
style={{
borderRadius: '28px',
clipPath: 'inset(0 50% 0 0 round 28px 0 0 28px)',
@@ -552,10 +552,10 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
<div
className="absolute bottom-3 inset-x-3 flex justify-between pointer-events-none z-20 text-[9px] font-mono font-bold uppercase tracking-wider text-white"
>
<span className="bg-slate-950/80 px-2 py-0.5 rounded backdrop-blur border border-white/10 shadow-xs">
<span className="bg-slate-950/85 px-2 py-0.5 rounded border border-white/10 shadow-xs">
BEFORE
</span>
<span className="bg-blue-600/90 px-2 py-0.5 rounded backdrop-blur border border-white/20 shadow-xs">
<span className="bg-blue-600 px-2 py-0.5 rounded border border-white/20 shadow-xs">
AFTER
</span>
</div>
@@ -567,7 +567,7 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
return (
<div
style={{ borderRadius: '28px' }}
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate [mask-image:radial-gradient(white,black)] [-webkit-mask-image:-webkit-radial-gradient(white,black)]"
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
>
<img
src={item.imageUrl || item.afterUrl || item.beforeUrl || '/brand/og-default.png'}
+6 -6
View File
@@ -230,7 +230,7 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
style={{ left: `${splitPos}%`, transform: 'translateX(-50%)' }}
>
{/* Sleek handle pill */}
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-5 h-5 sm:w-6 sm:h-6 rounded-full bg-white/95 backdrop-blur-sm text-slate-800 shadow-md flex items-center justify-center border border-slate-300">
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 w-5 h-5 sm:w-6 sm:h-6 rounded-full bg-white text-slate-800 shadow-md flex items-center justify-center border border-slate-300">
<div className="flex items-center gap-[2px]">
<div className="w-0 h-0 border-y-[2.5px] sm:border-y-[3px] border-y-transparent border-r-[3px] sm:border-r-[4px] border-r-slate-700" />
<div className="w-0 h-0 border-y-[2.5px] sm:border-y-[3px] border-y-transparent border-l-[3px] sm:border-l-[4px] border-l-slate-700" />
@@ -238,14 +238,14 @@ function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string })
</div>
</div>
{/* Floating badges */}
<span className="absolute bottom-2 sm:bottom-2.5 left-2 sm:left-2.5 bg-black/60 backdrop-blur-md text-[8px] sm:text-[9px] font-mono font-bold uppercase tracking-wider text-white px-1.5 sm:px-2 py-0.5 rounded-md border border-white/10 pointer-events-none shadow-sm">
{/* Floating badges (Hardware-accelerated, 0% CPU blur overhead) */}
<span className="absolute bottom-2 sm:bottom-2.5 left-2 sm:left-2.5 bg-black/80 text-[8px] sm:text-[9px] font-mono font-bold uppercase tracking-wider text-white px-1.5 sm:px-2 py-0.5 rounded-md border border-white/10 pointer-events-none shadow-sm">
Before
</span>
<span className="absolute bottom-2 sm:bottom-2.5 right-2 sm:right-2.5 bg-blue-600/90 backdrop-blur-md text-[8px] sm:text-[9px] font-mono font-bold uppercase tracking-wider text-white px-1.5 sm:px-2 py-0.5 rounded-md border border-white/20 pointer-events-none shadow-sm">
<span className="absolute bottom-2 sm:bottom-2.5 right-2 sm:right-2.5 bg-blue-600 text-[8px] sm:text-[9px] font-mono font-bold uppercase tracking-wider text-white px-1.5 sm:px-2 py-0.5 rounded-md border border-white/20 pointer-events-none shadow-sm">
CRE AI
</span>
<span className="hidden sm:inline-block absolute top-2.5 right-2.5 bg-white/90 backdrop-blur-md text-[9.5px] font-mono font-bold text-slate-800 px-2.5 py-0.5 rounded-full border border-slate-200 pointer-events-none shadow-sm opacity-0 group-hover:opacity-100 transition-opacity duration-200">
<span className="hidden sm:inline-block absolute top-2.5 right-2.5 bg-white text-[9.5px] font-mono font-bold text-slate-800 px-2.5 py-0.5 rounded-full border border-slate-200 pointer-events-none shadow-sm opacity-0 group-hover:opacity-100 transition-opacity duration-150">
Try Tool ↗
</span>
</div>
@@ -361,7 +361,7 @@ export function ToolGridSection({
{/* Persistent Sticky Search & Category Hub - Never disappears when scrolling */}
{(showCategoryFilter || showSearch) && (
<div className="sticky top-[52px] sm:top-[58px] z-30 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-2.5 sm:py-3 bg-[#FAF8F5]/95 backdrop-blur-md border-b border-slate-200/80 shadow-xs mb-8 sm:mb-12 transition-all">
<div className="sticky top-[52px] sm:top-[58px] z-30 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8 py-2.5 sm:py-3 bg-[#FAF8F5]/98 border-b border-slate-200/90 shadow-2xs mb-8 sm:mb-12 will-change-transform">
<div className="max-w-7xl mx-auto flex flex-col md:flex-row items-center justify-between gap-2.5 sm:gap-4">
{/* Category Navigation Pills */}
{showCategoryFilter && (
+32 -14
View File
@@ -17,18 +17,36 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
const pathname = usePathname();
// Track scroll position: transforms from text buttons into semi-solid navbar
// 100% Off-Main-Thread Observer: 0% CPU, 0 Scroll Lag
useEffect(() => {
const handleScroll = () => {
// On homepage, transform smoothly when scrolling towards the end of the hero image
const heroThreshold = typeof window !== 'undefined' ? Math.max(320, window.innerHeight * 0.7) : 450;
const threshold = pathname === '/' ? heroThreshold : 20;
setIsScrolled(window.scrollY > threshold);
};
// On non-homepage pages, navbar is immediately in solid state
if (pathname !== '/') {
setIsScrolled(true);
return;
}
handleScroll();
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
setIsScrolled(false);
const sentinel = document.getElementById('hero-sentinel');
if (!sentinel) {
const handleScroll = () => {
setIsScrolled(window.scrollY > 400);
};
window.addEventListener('scroll', handleScroll, { passive: true });
return () => window.removeEventListener('scroll', handleScroll);
}
const observer = new IntersectionObserver(
([entry]) => {
setIsScrolled(!entry.isIntersecting && entry.boundingClientRect.top < 0);
},
{
threshold: 0,
rootMargin: '-60px 0px 0px 0px',
}
);
observer.observe(sentinel);
return () => observer.disconnect();
}, [pathname]);
// Close mobile menu on Escape key
@@ -61,12 +79,12 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
return (
<header
className={`fixed top-0 left-0 right-0 w-full z-50 transition-all duration-300 pointer-events-auto ${
className={`fixed top-0 left-0 right-0 w-full z-50 transition-[background-color,border-color,padding] duration-200 pointer-events-auto ${
mobileMenuOpen
? 'bg-[#FAF8F5] border-b border-slate-200/90 shadow-sm'
? 'bg-[#FAF8F5] border-b border-slate-200/90 shadow-2xs'
: isHeroTransparent
? 'bg-transparent border-b border-transparent py-2 sm:py-3'
: 'bg-[#FAF8F5]/92 backdrop-blur-md border-b border-slate-200/80 shadow-sm py-2 sm:py-2.5'
? 'bg-transparent border-b border-transparent py-2.5 sm:py-3.5'
: 'bg-[#FAF8F5]/96 border-b border-slate-200/80 shadow-2xs py-2 sm:py-2.5'
}`}
>
<div className="max-w-[1640px] mx-auto px-4 sm:px-6 lg:px-10 flex items-center justify-between">
+5 -131
View File
@@ -7,122 +7,16 @@ interface SmoothScrollProviderProps {
}
/**
* Universal Smooth Scrolling Provider.
* - On iOS / Android / Tablets / Touch devices: Keeps native hardware-accelerated 120Hz momentum
* scrolling intact, completely avoiding WebKit JS scroll conflicts and parser overhead.
* - On Desktop & Trackpads: Dynamically loads high-performance exponential easing Lenis engine.
* - Idle sleep: Automatically stops the RAF loop when scrolling is settled (0% CPU at rest).
* Universal Native Smooth Scrolling Provider.
* - 100% native C++ browser momentum scrolling (120Hz / 60Hz hardware accelerated).
* - 0% CPU at rest and during scrolling (zero JS wheel hijacking, zero RAF loops).
* - Handles anchor link smooth scrolling safely across all devices.
*/
export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
useEffect(() => {
// Only run in client browser
if (typeof window === 'undefined') return;
let lenis: any = null;
let animId = 0;
let isDisposed = false;
let visibilityHandler: (() => void) | null = null;
let removeInputListeners: (() => void) | null = null;
// Detect mobile / touch devices: iOS (iPhone, iPad, iPod), Android tablets, and touch screens
const isTouchDevice =
'ontouchstart' in window ||
navigator.maxTouchPoints > 0 ||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
const prefersReducedMotion =
window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
// Only load Lenis for non-touch desktop environments that haven't requested reduced motion
if (!isTouchDevice && !prefersReducedMotion) {
import('lenis')
.then(({ default: Lenis }) => {
if (isDisposed) return;
try {
lenis = new Lenis({
duration: 1.15,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
syncTouch: false,
wheelMultiplier: 0.95,
touchMultiplier: 1.0,
infinite: false,
});
(window as any).__lenis = lenis;
let isRunning = false;
let idleFrames = 0;
const startRaf = () => {
if (isRunning || isDisposed || document.hidden) return;
isRunning = true;
idleFrames = 0;
const raf = (time: number) => {
if (isDisposed || document.hidden) {
isRunning = false;
animId = 0;
return;
}
lenis?.raf(time);
// Idle Sleep: when scrolling velocity settles to 0, stop RAF loop to conserve battery
if (lenis && Math.abs(lenis.velocity || 0) < 0.01 && !lenis.isScrolling) {
idleFrames++;
if (idleFrames > 20) {
isRunning = false;
animId = 0;
return;
}
} else {
idleFrames = 0;
}
animId = requestAnimationFrame(raf);
};
animId = requestAnimationFrame(raf);
};
// Wake up loop on scroll interactions
const wakeUp = () => startRaf();
window.addEventListener('wheel', wakeUp, { passive: true });
window.addEventListener('keydown', wakeUp, { passive: true });
window.addEventListener('scroll', wakeUp, { passive: true });
removeInputListeners = () => {
window.removeEventListener('wheel', wakeUp);
window.removeEventListener('keydown', wakeUp);
window.removeEventListener('scroll', wakeUp);
};
startRaf();
visibilityHandler = () => {
if (document.hidden) {
isRunning = false;
if (animId) {
cancelAnimationFrame(animId);
animId = 0;
}
} else {
startRaf();
}
};
document.addEventListener('visibilitychange', visibilityHandler);
} catch {
// Graceful fallback to native scrolling
}
})
.catch(() => {
// Graceful fallback if dynamic import fails
});
}
// Universal anchor link handler (safe on text nodes and SVG elements across mobile & desktop)
// Universal anchor link handler using native hardware-accelerated smooth scroll
const handleAnchorClick = (e: MouseEvent) => {
try {
const target = e.target as Node | null;
@@ -140,15 +34,7 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
const targetElement = document.querySelector(href);
if (targetElement) {
e.preventDefault();
if (lenis && typeof lenis.scrollTo === 'function') {
lenis.scrollTo(targetElement as HTMLElement, {
offset: -80,
duration: 1.25,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
});
} else {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
targetElement.scrollIntoView({ behavior: 'smooth' });
}
} catch {
// Fallback gracefully
@@ -158,19 +44,7 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
document.addEventListener('click', handleAnchorClick, { capture: true });
return () => {
isDisposed = true;
if (animId) cancelAnimationFrame(animId);
if (visibilityHandler) {
document.removeEventListener('visibilitychange', visibilityHandler);
}
if (removeInputListeners) {
removeInputListeners();
}
document.removeEventListener('click', handleAnchorClick, { capture: true });
if (lenis && typeof lenis.destroy === 'function') {
lenis.destroy();
}
delete (window as any).__lenis;
};
}, []);