[英]How to enable http2 protocol in nuxt.js
How to enable http2 protocol in nuxt.js app?如何在 nuxt.js 应用程序中启用 http2 协议? I have added SSL certificates and enabled modern mode, played with render>http2 settings in nuxt.config.js, but no matter what I try app still serves request with standard http/1.1 protocol.
我已经添加了 SSL 证书并启用了现代模式,在 nuxt.config.js 中使用了 render>http2 设置,但无论我尝试什么,应用程序仍然使用标准的 http/1.1 协议提供请求。 I can't seem to find anything about it in the documentation either.
我似乎也无法在文档中找到任何相关信息。
Here is my nuxt.config.js:这是我的 nuxt.config.js:
import path from 'path'
import fs from 'fs'
export default {
server: {
https: {
key: fs.readFileSync(path.resolve(__dirname, 'certs/localhost.key')),
cert: fs.readFileSync(path.resolve(__dirname, 'certs/localhost.crt'))
}
},
mode: 'universal',
modern: true,
render: {
http2: {
push: true, pushAssets: null
}
},
/*
** Headers of the page
*/
head: {
title: process.env.npm_package_name || '',
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width, initial-scale=1'},
{hid: 'description', name: 'description', content: process.env.npm_package_description || ''}
],
link: [
{rel: 'icon', type: 'image/x-icon', href: '/favicon.ico'}
]
},
/*
** Customize the progress-bar color
*/
loading: {color: '#fff'},
/*
** Global CSS
*/
css: [
],
/*
** Plugins to load before mounting the App
*/
plugins: [
],
/*
** Nuxt.js dev-modules
*/
buildModules: [
// Doc: https://github.com/nuxt-community/eslint-module
'@nuxtjs/eslint-module',
// Doc: https://github.com/nuxt-community/nuxt-tailwindcss
'@nuxtjs/tailwindcss'
],
/*
** Nuxt.js modules
*/
modules: [
// Doc: https://axios.nuxtjs.org/usage
'@nuxtjs/axios',
'@nuxtjs/pwa',
// Doc: https://github.com/nuxt-community/dotenv-module
'@nuxtjs/dotenv'
],
/*
** Axios module configuration
** See https://axios.nuxtjs.org/options
*/
axios: {
},
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
}
}
}
Thank in advance.预先感谢。
You should set your mode to modern:您应该将模式设置为现代:
mode: 'modern'
And specify in the render.http2.pushAssets the actual assets that should be pushed (you currently have null in your sample code).并在 render.http2.pushAssets 中指定应推送的实际资产(您当前的示例代码中有 null)。
For example:例如:
export default {
// ...
render: {
http2: {
push: true,
pushAssets: [
'/css/main.css',
'/js/main.js'
]
}
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.