mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
Add resourceHints for SPA mode
This commit is contained in:
parent
c9e8d44c45
commit
696ada09c4
@ -55,18 +55,23 @@ export default class MetaRenderer {
|
||||
meta.BODY_ATTRS = m.bodyAttrs.text()
|
||||
// HEAD tags
|
||||
meta.HEAD = m.meta.text() + m.title.text() + m.link.text() + m.style.text() + m.script.text() + m.noscript.text()
|
||||
// Resources Hints
|
||||
meta.resourceHints = ''
|
||||
// Resource Hints
|
||||
const clientManifest = this.renderer.resources.clientManifest
|
||||
if (this.options.render.resourceHints && clientManifest) {
|
||||
const publicPath = clientManifest.publicPath || '/_nuxt/'
|
||||
// Pre-Load initial resources
|
||||
if (Array.isArray(clientManifest.initial)) {
|
||||
meta.HEAD += clientManifest.initial.map(r => `<link rel="preload" href="${publicPath}${r}" as="script" />`).join('')
|
||||
meta.resourceHints += clientManifest.initial.map(r => `<link rel="preload" href="${publicPath}${r}" as="script" />`).join('')
|
||||
}
|
||||
|
||||
// Pre-Fetch async resources
|
||||
if (Array.isArray(clientManifest.async)) {
|
||||
meta.HEAD += clientManifest.async.map(r => `<link rel="prefetch" href="${publicPath}${r}" />`).join('')
|
||||
meta.resourceHints += clientManifest.async.map(r => `<link rel="prefetch" href="${publicPath}${r}" />`).join('')
|
||||
}
|
||||
// Add them to HEAD
|
||||
if (meta.resourceHints) {
|
||||
meta.HEAD += meta.resourceHints
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -453,7 +453,7 @@ export default class Renderer extends Tapable {
|
||||
// Basic response if SSR is disabled or spa data provided
|
||||
const spa = context.spa || (context.res && context.res.spa)
|
||||
if (this.noSSR || spa) {
|
||||
const { HTML_ATTRS, BODY_ATTRS, HEAD } = await this.metaRenderer.render(context)
|
||||
const { HTML_ATTRS, BODY_ATTRS, HEAD, resourceHints } = await this.metaRenderer.render(context)
|
||||
const APP = `<div id="__nuxt">${this.resources.loadingHTML}</div>`
|
||||
|
||||
const data = {
|
||||
@ -465,7 +465,7 @@ export default class Renderer extends Tapable {
|
||||
|
||||
const html = this.resources.spaTemplate(data)
|
||||
|
||||
return { html }
|
||||
return { html, resourceHints }
|
||||
}
|
||||
|
||||
// Call renderToString from the bundleRenderer and generate the HTML (will update the context as well)
|
||||
|
Loading…
Reference in New Issue
Block a user