dvAfterBootDownloadsDetector top-level constant
String
const dvAfterBootDownloadsDetector
A JavaScript function dvAfterBoot(go) that calls go once, when the
page has downloaded both the app (dvBootAppPattern) and its renderer
(dvBootRendererPattern).
What the first frame needs besides those two -- the fonts, the manifests,
a route's deferred modules -- is asked for early so it is there when the
app wants it, but not before them: on a slow network every byte competes,
and preloads sharing the line with main.dart.wasm delayed it by 10 s on
Slow 3G (sigmadev.digital, HTTP/1.1). Where the browser cannot report
downloads, go never runs and the app fetches everything itself, as it
always did.
Implementation
const String dvAfterBootDownloadsDetector = 'function dvAfterBoot(go){'
'var m=0,r=0,done=0;'
'function seen(n){if(/$dvBootAppPattern/.test(n))m=1;'
'if(/$dvBootRendererPattern/.test(n))r=1;'
'if(m&&r&&!done){done=1;go()}}'
'try{performance.getEntriesByType("resource").forEach(function(e){seen(e.name)});'
'new PerformanceObserver(function(l){l.getEntries().forEach(function(e){seen(e.name)})})'
'.observe({type:"resource",buffered:true})}catch(e){}}';