-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
42 lines (36 loc) · 1.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as scope from './lib/scope.js'
import * as polite from './lib/polite.js'
import * as preloader from './lib/preloader.js'
import * as payloader from './lib/payloader.js'
/*
* NOTE:
*
* This class expects window-scoped methods to exist
*
*/
// callback to allow control of when polite-load launches
let preloaderComplete
const begin = async () => {
await polite.prepare(window.adParams.politeLoadAfter)
// prepare vendor onload (Network.js)
await window.prepareIndex()
// prepare scope
scope.prepare()
// misc index control
await window.prepareAdParamsMisc()
// prepare network
await window.prepareNetworkExit()
// prepare preloader
const preloaders = await preloader.loadPreloaders(window.assets)
// allow index custom preloader routines to resolve
preloaderComplete = window.preparePreloader(preloaders) || Promise.resolve()
// finish polite timeout (some networks require delay before asset load)
await polite.resolveDelay()
// load build payloads: fonts, scripts, images, binaries
const assets = await payloader.loadAssets(window.assets)
// preload complete
await preloaderComplete
// launch polite
window.onImpression({ ...assets, preloaders })
}
begin()