@@ -35,15 +35,20 @@ const enum BundleImportState {
3535 Loading ,
3636}
3737type BundleImport = {
38+ $name$ : string ;
3839 $url$ : string | null ;
3940 $state$ : BundleImportState ;
4041 $imports$ : string [ ] ;
4142 $dynamicImports$ : string [ ] ;
43+ $created$ ?: number | null ;
4244} ;
4345const bundles = new Map < string , BundleImport > ( ) ;
4446const high : BundleImport [ ] = [ ] ;
4547const low : BundleImport [ ] = [ ] ;
4648
49+ const log = ( ...args : any [ ] ) => {
50+ console . log ( `PL> ${ high . length } hi ${ low . length } lo` , ...args ) ;
51+ } ;
4752let base : string | undefined ;
4853
4954// minification helpers
@@ -86,8 +91,11 @@ const preloadOne = (bundle: BundleImport, priority?: boolean) => {
8691 return ;
8792 }
8893 if ( bundle . $url$ ) {
89- const start = performance . now ( ) ;
90- console . log ( '>> preloadOne' , bundle . $url$ , priority ) ;
94+ const start = Date . now ( ) ;
95+ log (
96+ `load ${ priority ? 'high' : 'low' } after ${ `${ start - bundle . $created$ ! } ms` } ` ,
97+ bundle . $name$
98+ ) ;
9199 const link = doc . createElement ( 'link' ) ;
92100 link . href = bundle . $url$ ! ;
93101 link . rel = rel ;
@@ -98,8 +106,8 @@ const preloadOne = (bundle: BundleImport, priority?: boolean) => {
98106 }
99107 link . as = 'script' ;
100108 link . onload = link . onerror = ( ) => {
101- const end = performance . now ( ) ;
102- console . log ( '<< preloadOne done' , bundle . $url$ , priority , ` $ {end - start } ms`) ;
109+ const end = Date . now ( ) ;
110+ log ( `DONE $ {end - start } ms`, bundle . $name$ ) ;
103111 link . remove ( ) ;
104112 if ( priority ) {
105113 highCount -- ;
@@ -126,10 +134,12 @@ const preloadOne = (bundle: BundleImport, priority?: boolean) => {
126134const makeBundle = ( path : string , imports : string [ ] , dynamicImports : string [ ] ) => {
127135 const url = path . endsWith ( '.js' ) ? new URL ( `${ base } ${ path } ` , doc . baseURI ) . toString ( ) : null ;
128136 return {
137+ $name$ : path ,
129138 $url$ : url ,
130139 $state$ : BundleImportState . None ,
131140 $imports$ : imports ,
132141 $dynamicImports$ : dynamicImports ,
142+ $created$ : Date . now ( ) ,
133143 } ;
134144} ;
135145const ensureBundle = ( name : string ) => {
@@ -186,13 +196,10 @@ const parseBundleGraph = (text: string, base: string) => {
186196 * @internal
187197 */
188198const preload = ( name : string | string [ ] , priority ?: boolean ) => {
189- if ( ! isBrowser || ! base ) {
199+ if ( ! isBrowser || ! base || ! name . length ) {
190200 return ;
191201 }
192202 const queue = priority ? high : low ;
193- console . log (
194- `preload queue ${ name } ${ priority ? 'high' : 'low' } - high ${ high . length } low ${ low . length } `
195- ) ;
196203 if ( Array . isArray ( name ) ) {
197204 queue . push ( ...( name . map ( ensureBundle ) . filter ( Boolean ) as BundleImport [ ] ) . reverse ( ) ) ;
198205 } else {
@@ -201,6 +208,7 @@ const preload = (name: string | string[], priority?: boolean) => {
201208 queue . push ( bundle ) ;
202209 }
203210 }
211+ log ( `queue ${ priority ? 'high' : 'low' } ` , name ) ;
204212 trigger ( ) ;
205213} ;
206214
0 commit comments