MCPcopy
hub / github.com/QwikDev/qwik / trigger

Function trigger

packages/qwik/src/core/preloader/queue.ts:71–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69 * We make sure to first preload the high priority items.
70 */
71export const trigger = () => {
72 if (!queue.length) {
73 return;
74 }
75 sortQueue();
76 while (queue.length) {
77 const bundle = queue[0];
78 const inverseProbability = bundle.$inverseProbability$;
79 const probability = 1 - inverseProbability;
80 const allowedPreloads = graph
81 ? config.$maxIdlePreloads$
82 : // While the graph is not available, we limit to 5 preloads
83 5;
84 // When we're 99% sure, everything needs to be queued
85 if (probability >= 0.99 || preloadCount < allowedPreloads) {
86 queue.shift();
87 preloadOne(bundle);
88 } else {
89 break;
90 }
91 }
92 /**
93 * The low priority bundles are opportunistic, and we want to give the browser some breathing room
94 * for other resources, so we cycle between 4 and 10 outstanding modulepreloads.
95 */
96 if (config.$DEBUG$ && !queue.length) {
97 const loaded = [...bundles.values()].filter((b) => b.$state$ > BundleImportState_None);
98 const waitTime = loaded.reduce((acc, b) => acc + b.$waitedMs$, 0);
99 const loadTime = loaded.reduce((acc, b) => acc + b.$loadedMs$, 0);
100 log(
101 `>>>> done ${loaded.length}/${bundles.size} total: ${waitTime}ms waited, ${loadTime}ms loaded`
102 );
103 }
104};
105
106const preloadOne = (bundle: BundleImport) => {
107 if (bundle.$state$ >= BundleImportState_Preload) {

Callers 3

loadBundleGraphFunction · 0.90
preloadOneFunction · 0.70
preloadFunction · 0.70

Calls 3

sortQueueFunction · 0.85
preloadOneFunction · 0.85
logFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…