Google App Engine 标准不压缩我的 Next.js/Express 应用程序
Google App Engine standard doesn't compress my Next.js/Express app
我正在想办法让 Google App Engine(标准版)对我的 Next.js/Node.js/Express 应用程序的输出应用压缩。
据我所知,问题是
1) Google 的负载均衡器从请求中删除了所有指示客户端支持压缩的元标记,因此 server.js
中的 app.use(compression())
不会执行任何操作。我尝试使用 {filter: shouldCompress}
函数强制压缩,但似乎并不重要,因为 Google 的前端 still returns an未压缩的结果。 (本地压缩效果很好。)
2) Google 的负载均衡器如何以及何时选择应用压缩对我来说是个谜。 (特别是,为什么不看我愚蠢但庞大的 application/javascsript
内容 :))
这是他们在文档中所说的内容:
If the client sends HTTP headers with the original request indicating
that the client can accept compressed (gzipped) content, App Engine
compresses the handler response data automatically and attaches the
appropriate response headers. It uses both the Accept-Encoding and
User-Agent request headers to determine if the client can reliably
receive compressed responses.
How Requests are Handled: Response Compression
就是这样。我很想在这个项目中使用 App Engine,但是当 index.js 是 700KB 而不是压缩后的 200KB 时,它有点像一个 showstopper。
根据 Node.js 的 Request Headers and Responses documentation,出于安全目的,Accept-Encoding header 已从请求中删除。
Note: Entity headers (headers relating to the request body) are not sanitized or checked, so applications should not rely on them. In particular, the Content- MD5 request header is sent unmodified to the application, so may not match the MD5 hash of the content. Also, the Content-Encoding request header is not checked by the server, so if the client sends a gzipped request body, it will be sent in compressed form to the application.
另请注意 Google Group 上的回复,其中指出:
Today, we are not passing through the Accept-Encoding
header, so it is not possible for your middleware to decide that it should compress.
We will roll out a fix for this in the new few weeks.
我正在想办法让 Google App Engine(标准版)对我的 Next.js/Node.js/Express 应用程序的输出应用压缩。
据我所知,问题是
1) Google 的负载均衡器从请求中删除了所有指示客户端支持压缩的元标记,因此 server.js
中的 app.use(compression())
不会执行任何操作。我尝试使用 {filter: shouldCompress}
函数强制压缩,但似乎并不重要,因为 Google 的前端 still returns an未压缩的结果。 (本地压缩效果很好。)
2) Google 的负载均衡器如何以及何时选择应用压缩对我来说是个谜。 (特别是,为什么不看我愚蠢但庞大的 application/javascsript
内容 :))
这是他们在文档中所说的内容:
If the client sends HTTP headers with the original request indicating that the client can accept compressed (gzipped) content, App Engine compresses the handler response data automatically and attaches the appropriate response headers. It uses both the Accept-Encoding and User-Agent request headers to determine if the client can reliably receive compressed responses. How Requests are Handled: Response Compression
就是这样。我很想在这个项目中使用 App Engine,但是当 index.js 是 700KB 而不是压缩后的 200KB 时,它有点像一个 showstopper。
根据 Node.js 的 Request Headers and Responses documentation,出于安全目的,Accept-Encoding header 已从请求中删除。
Note: Entity headers (headers relating to the request body) are not sanitized or checked, so applications should not rely on them. In particular, the Content- MD5 request header is sent unmodified to the application, so may not match the MD5 hash of the content. Also, the Content-Encoding request header is not checked by the server, so if the client sends a gzipped request body, it will be sent in compressed form to the application.
另请注意 Google Group 上的回复,其中指出:
Today, we are not passing through the
Accept-Encoding
header, so it is not possible for your middleware to decide that it should compress.We will roll out a fix for this in the new few weeks.