@@ -31,44 +31,44 @@ async function beginPreloading() {
31
31
progressIndicator . style . width = '0%' ;
32
32
progressText . textContent = `Loaded ${ loadedAssets } of ${ totalAssets } assets` ;
33
33
34
- function reportProgress ( ) {
35
- loadedAssets ++ ;
34
+ for ( let i = 0 ; i < assets . length ; i += batchSize ) {
35
+ const batch = assets . slice ( i , i + batchSize ) ;
36
+ await loadBatch ( batch ) ;
37
+ }
38
+ }
36
39
37
- const value = Math . floor ( ( loadedAssets / totalAssets ) * 100 ) + '%' ;
38
- progressIndicator . style . width = value ;
40
+ function reportProgress ( ) {
41
+ loadedAssets ++ ;
39
42
40
- progressText . textContent = `Loaded ${ loadedAssets } of ${ totalAssets } assets` ;
41
- }
43
+ const value = Math . floor ( ( loadedAssets / totalAssets ) * 100 ) + '%' ;
44
+ progressIndicator . style . width = value ;
42
45
43
- async function load ( url ) {
44
- try {
45
- const response = await fetch ( url ) ;
46
- if ( ! response . ok ) {
47
- throw new Error (
48
- `Failed to load: ${ response . status } ${ response . statusText } ` ,
49
- ) ;
50
- }
51
- return await response . text ( ) ;
52
- } catch ( error ) {
53
- throw new Error ( "Network error" ) ;
54
- }
55
- }
46
+ progressText . textContent = `Loaded ${ loadedAssets } of ${ totalAssets } assets` ;
47
+ }
56
48
57
- async function loadBatch ( urls ) {
58
- const loadPromises = urls . map ( async ( url ) => {
59
- await load ( url ) ;
60
- reportProgress ( ) ;
61
- } ) ;
62
- try {
63
- return await Promise . all ( loadPromises ) ;
64
- } catch ( error ) {
65
- console . error ( 'Error loading one or more asset:' , error ) ;
49
+ async function load ( url ) {
50
+ try {
51
+ const response = await fetch ( url ) ;
52
+ if ( ! response . ok ) {
53
+ throw new Error (
54
+ `Failed to load: ${ response . status } ${ response . statusText } ` ,
55
+ ) ;
66
56
}
57
+ return await response . text ( ) ;
58
+ } catch ( error ) {
59
+ throw new Error ( "Network error" ) ;
67
60
}
61
+ }
68
62
69
- for ( let i = 0 ; i < assets . length ; i += batchSize ) {
70
- const batch = assets . slice ( i , i + batchSize ) ;
71
- await loadBatch ( batch ) ;
63
+ async function loadBatch ( urls ) {
64
+ const loadPromises = urls . map ( async ( url ) => {
65
+ await load ( url ) ;
66
+ reportProgress ( ) ;
67
+ } ) ;
68
+ try {
69
+ return await Promise . all ( loadPromises ) ;
70
+ } catch ( error ) {
71
+ console . error ( 'Error loading one or more asset:' , error ) ;
72
72
}
73
73
}
74
74
0 commit comments