Skip to content

feat(ssr): add 'renderCriticalStyles' function for template #7462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/server/template-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,24 @@ export default class TemplateRenderer {
}
}

renderStyles (context: Object): string {
renderCriticalStyles (context: Object): string {
// context.styles is a getter exposed by vue-style-loader which contains
// the inline component styles collected during SSR
return (context.styles || '')
}

renderStyleLinks (context: Object): string {
const initial = this.preloadFiles || []
const async = this.getUsedAsyncFiles(context) || []
const cssFiles = initial.concat(async).filter(({ file }) => isCSS(file))
return (
// render links for css files
(cssFiles.length
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}${file}">`).join('')
: '') +
// context.styles is a getter exposed by vue-style-loader which contains
// the inline component styles collected during SSR
(context.styles || '')
)

return cssFiles.length
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}${file}">`).join('')
: ''
}

renderStyles (context: Object): string {
return this.renderStyleLinks(context) + this.renderCriticalStyles(context)
}

renderResourceHints (context: Object): string {
Expand Down