1
1
import React from 'react'
2
2
import htmlescape from 'htmlescape'
3
+ import pkg from '../../package.json'
3
4
4
5
export default ( { head, css, html, data, dev, staticMarkup} ) => {
6
+ let script
7
+ if ( ! staticMarkup ) {
8
+ if ( dev ) {
9
+ script = < script type = 'text/javascript' src = '/_next/next-dev.bundle.js' />
10
+ } else {
11
+ script = < script dangerouslySetInnerHTML = { { __html :`
12
+ (function () {
13
+ load('https://cdn.zeit.co/next.js/${ pkg . version } /next.min.js', function (err) {
14
+ if (err) load('/_next/next.bundle.js')
15
+ })
16
+
17
+ function load (src, fn) {
18
+ fn = fn || function () {}
19
+ var script = document.createElement('script')
20
+ script.src = src
21
+ script.onload = function () { fn(null) }
22
+ script.onerror = fn
23
+ script.crossorigin = 'anonymous'
24
+ document.head.appendChild(script)
25
+ }
26
+ })()
27
+ ` } } />
28
+ }
29
+ }
30
+
5
31
return < html >
6
32
< head >
7
33
{ ( head || [ ] ) . map ( ( h , i ) => React . cloneElement ( h , { key :i } ) ) }
@@ -10,7 +36,7 @@ export default ({ head, css, html, data, dev, staticMarkup }) => {
10
36
< body >
11
37
< div id = '__next' dangerouslySetInnerHTML = { { __html :html } } />
12
38
{ staticMarkup ?null :< script dangerouslySetInnerHTML = { { __html :'__NEXT_DATA__ = ' + htmlescape ( data ) } } /> }
13
- { staticMarkup ? null : < script type = 'text/javascript' src = { dev ? '/_next/next-dev.bundle.js' : '/_next/next.bundle.js' } /> }
39
+ { script }
14
40
</ body >
15
41
</ html >
16
42
}