mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
feat(http2): add render.http2.push option
This option disables http2 push headers by default as is currently inconsistent with different browser and webservers
This commit is contained in:
parent
5763d21905
commit
349f6e6219
@ -51,6 +51,9 @@ class Nuxt {
|
||||
scrollBehavior: null
|
||||
},
|
||||
render: {
|
||||
http2: {
|
||||
push: false
|
||||
},
|
||||
static: {},
|
||||
gzip: {
|
||||
threshold: 0
|
||||
@ -66,11 +69,11 @@ class Nuxt {
|
||||
}
|
||||
// Sanitization
|
||||
if (options.loading === true) delete options.loading
|
||||
if (options.router && typeof options.router.middleware === 'string') options.router.middleware = [ options.router.middleware ]
|
||||
if (options.router && typeof options.router.middleware === 'string') options.router.middleware = [options.router.middleware]
|
||||
if (options.router && typeof options.router.base === 'string') {
|
||||
this._routerBaseSpecified = true
|
||||
}
|
||||
if (typeof options.transition === 'string') options.transition = { name: options.transition }
|
||||
if (typeof options.transition === 'string') options.transition = {name: options.transition}
|
||||
this.options = _.defaultsDeep(options, defaults)
|
||||
// Ready variable
|
||||
this._ready = false
|
||||
|
@ -74,8 +74,8 @@ export async function render (req, res) {
|
||||
}
|
||||
res.setHeader('ETag', etag)
|
||||
}
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(html))
|
||||
// HTTP2 push headers
|
||||
if(!error && this.options.render.http2.push) {
|
||||
// Parse resourceHints to extract HTTP.2 prefetch/push headers
|
||||
// https://w3c.github.io/preload/#server-push-http-2
|
||||
const regex = /link rel="([^"]*)" href="([^"]*)" as="([^"]*)"/g
|
||||
@ -88,6 +88,9 @@ export async function render (req, res) {
|
||||
}
|
||||
}
|
||||
res.setHeader('Link', pushAssets)
|
||||
}
|
||||
res.setHeader('Content-Type', 'text/html; charset=utf-8')
|
||||
res.setHeader('Content-Length', Buffer.byteLength(html))
|
||||
res.end(html, 'utf8')
|
||||
return html
|
||||
} catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user