Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebecbcf

Browse files
nkzawarauchg
authored andcommitted
Load client js from cdn with fallback (vercel#34)
* load client js from cdn with fallback* fix cdn url
1 parent08811c7 commitebecbcf

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

‎lib/document.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,33 @@
11
importReactfrom'react'
22
importhtmlescapefrom'htmlescape'
3+
importpkgfrom'../../package.json'
34

45
exportdefault({ head, css, html, data, dev, staticMarkup})=>{
6+
letscript
7+
if(!staticMarkup){
8+
if(dev){
9+
script=<scripttype='text/javascript'src='/_next/next-dev.bundle.js'/>
10+
}else{
11+
script=<scriptdangerouslySetInnerHTML={{__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+
531
return<html>
632
<head>
733
{(head||[]).map((h,i)=>React.cloneElement(h,{key:i}))}
@@ -10,7 +36,7 @@ export default ({ head, css, html, data, dev, staticMarkup }) => {
1036
<body>
1137
<divid='__next'dangerouslySetInnerHTML={{__html:html}}/>
1238
{staticMarkup ?null :<scriptdangerouslySetInnerHTML={{__html:'__NEXT_DATA__ = '+htmlescape(data)}}/>}
13-
{staticMarkup ?null :<scripttype='text/javascript'src={dev ?'/_next/next-dev.bundle.js' :'/_next/next.bundle.js'}/>}
39+
{script}
1440
</body>
1541
</html>
1642
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp