Skip to content

Commit 4d81fa8

Browse files
committed
ssr: expose getPreloadFiles() on context
1 parent a45e40d commit 4d81fa8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/server/template-renderer/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ export default class TemplateRenderer {
6666
;['ResourceHints', 'State', 'Scripts', 'Styles'].forEach(type => {
6767
context[`render${type}`] = renderer[`render${type}`].bind(renderer, context)
6868
})
69+
// also expose getPreloadFiles, useful for HTTP/2 push
70+
context.getPreloadFiles = renderer.getPreloadFiles.bind(renderer, context)
6971
}
7072

7173
// render synchronously given rendered app content and render context
@@ -116,10 +118,19 @@ export default class TemplateRenderer {
116118
return this.renderPreloadLinks(context) + this.renderPrefetchLinks(context)
117119
}
118120

119-
renderPreloadLinks (context: Object): string {
121+
getPreloadFiles (context: Object) {
120122
const usedAsyncFiles = this.getUsedAsyncFiles(context)
121123
if (this.preloadFiles || usedAsyncFiles) {
122-
return (this.preloadFiles || []).concat(usedAsyncFiles || []).map(file => {
124+
return (this.preloadFiles || []).concat(usedAsyncFiles || [])
125+
} else {
126+
return []
127+
}
128+
}
129+
130+
renderPreloadLinks (context: Object): string {
131+
const files = this.getPreloadFiles(context)
132+
if (files.length) {
133+
return files.map(file => {
123134
let extra = ''
124135
const withoutQuery = file.replace(/\?.*/, '')
125136
const ext = path.extname(withoutQuery).slice(1)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy