-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathinlineJSBlocking.scala.html
51 lines (35 loc) · 1.78 KB
/
inlineJSBlocking.scala.html
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
43
44
45
46
47
48
49
50
51
@import common.InlineJs
@import conf.switches.Switches.{AsyncCss, FontSwitch}
@import templates.inlineJS.blocking.js.{applyRenderConditions, config, enableStylesheets, shouldEnhance, loadApp}
@import templates.inlineJS.blocking.polyfills.js.{details, raf, setTimeout}
@()(implicit page: model.Page, request: RequestHeader, context: model.ApplicationContext)
@* NOTE the order of these includes is important *@
<script id="gu">
// ************* POLYFILLS *************
// Mostly handled by polyfill.io below. These are needed for inline JS though, so cannot rely on pf.io
// It's faster to pass arguments in setTimeout than to use an anon function, but IE <10 can't do that.
// Used by RAF polyfill.
@Html(setTimeout().body)
// Pollyfill requestAnimationFrame
@InlineJs(raf().body, "raf.js")
// Polyfill details
@InlineJs(details().body, "details.js")
// ************* RENDER-CRITICAL BLOCKING JS *************
// determine whether to run enhanced JS
@InlineJs(shouldEnhance(page.metadata).body, "shouldEnhance.js")
// page config
// creates window.guardian
@Html(config(page).body)
// record the number of times the browser goes offline during a pageview
window.guardian.offlineCount = 0;
window.addEventListener('offline', function incrementOfflineCount () { window.guardian.offlineCount++ });
// apply render conditions
@InlineJs(applyRenderConditions().body, "applyRenderConditions.js")
@if(AsyncCss.isSwitchedOn) {
// enable non-blocking stylesheets
// borrows *heavily* from https://github.com/filamentgroup/loadCSS.
@InlineJs(enableStylesheets().body, "enableStylesheets.js")
}
// ************* LOAD THE MAIN APP ASYNC *************
@InlineJs(loadApp().body, "loadApp.js")
</script>