File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // Performance monitoring utilities
2+
3+ export function measurePerformance ( label : string ) : ( ) => number {
4+ const start = performance . now ( ) ;
5+ return ( ) => {
6+ const duration = performance . now ( ) - start ;
7+ console . log ( `[Perf] ${ label } : ${ duration . toFixed ( 2 ) } ms` ) ;
8+ return duration ;
9+ } ;
10+ }
11+
12+ export function lazyLoadImage ( src : string ) : Promise < HTMLImageElement > {
13+ return new Promise ( ( resolve , reject ) => {
14+ const img = new Image ( ) ;
15+ img . onload = ( ) => resolve ( img ) ;
16+ img . onerror = reject ;
17+ img . src = src ;
18+ } ) ;
19+ }
20+
21+ export function preloadRoute ( importFn : ( ) => Promise < unknown > ) : void {
22+ if ( 'requestIdleCallback' in window ) {
23+ ( window as unknown as { requestIdleCallback : ( cb : ( ) => void ) => void } ) . requestIdleCallback ( ( ) => importFn ( ) ) ;
24+ } else {
25+ setTimeout ( importFn , 200 ) ;
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments