我目前正在使用 nuxt.js(使用内置服务器)构建应用程序。也就是说,我一直在通过开发运行谷歌灯塔,而在我的一生中,我无法让它为 http/2 服务。
里面nuxt.config.js
我补充说:
render: {
http2: {
push: true,
pushAssets: (req, res, publicPath, preloadFiles) => preloadFiles
.filter(f => f.asType === 'script' && f.file === 'runtime.js')
.map(f => `<${publicPath}${f.file}>; rel=preload; as=${f.asType}`)
}
}
也许我不明白 HTTP/2 如何与 nuxt 一起工作,如果有人能提供任何帮助或建议,那就太好了!
最佳答案
在撰写本文时,Nuxt 似乎不支持直接提供 HTTP/2。
很可能是因为通常在边缘(负载平衡器、CDN 等)上启用了 HTTP/2,它使用 HTTP/1(more info)与您的 Nuxt 服务器通信。
不过,您可以为 Nuxt 应用程序启用 HTTP/2 设置 Nginx 代理服务器:
server {
server_name localhost_http2;
listen 3001 ssl http2;
ssl_certificate /pathTo/server.crt;
ssl_certificate_key /pathTo/server.key;
location / {
# url of nuxt app
proxy_pass http://localhost:3000/;
proxy_buffering off;
proxy_http_version 1.1;
}
}
关于javascript - Nuxt.JS http/2 帮助和建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60062186/