使用Firebase托管+ Cloud Run Express服务器时,在哪里设置Cache-Control? [英] Where to set Cache-Control when using Firebase Hosting + Cloud Run express server?
问题描述
在使用Firebase Hosting + Cloud Run(快速服务器)时,Firebase Hosting的行为就像客户端和服务器之间的代理.
我应该在哪里设置 Cache-Control
标头?
- 在
firebase.json
中配置Firebase托管 - 或者我应该在Cloud Run上的快递服务器中使用
res.set("Cache-Control")
吗?
您可以同时使用两种方法.但是,无论您在 firebase.json
上设置的内容如何,都会覆盖您在 express
代码上设置的内容.
例如:
例如,如果您没有将任何 Cache-Control
添加到您的 firebase.json
中,而是添加了 res.set("Cache-Control";,"no-cache")
,根据您的期望,您的响应将是 no-cache
.
但是,如果您同时在 firebase.json
中添加类似的内容,它将覆盖您的 res.set()
调用:
{"source":"/**",标题":[{"key":"Cache-Control",价值":公开"//甚至即使您明确设置了私人",还是默认}]//它会覆盖您使用res.set()在服务器上设置的内容}
When you are using Firebase Hosting + Cloud Run (express server), Firebase Hosting behaves like a proxy between your client and your server.
Where should I set my Cache-Control
header?
- In
firebase.json
to configure Firebase Hosting - Or should I use
res.set("Cache-Control")
in my express server over on Cloud Run?
You can do it both ways. But whatever you set on firebase.json
will overwrite what you set on your express
code.
For example: the default Cache-Control
on Firebase Hosting is private
.
For example, if you don't add any Cache-Control
to your firebase.json
and you add res.set("Cache-Control","no-cache");
to your express response, your response will be no-cache
, as you intended.
But if at the same time your add something like this to your firebase.json
, it will overwrite your res.set()
call:
{
"source": "/**",
"headers": [{
"key": "Cache-Control",
"value": "public" // OR EVEN IF YOU EXPLICITLY SET "private", WHICH IS THE DEFAULT
}] // IT WILL OVERWRITE WHAT YOU SET ON YOUR SERVER WITH res.set()
}
这篇关于使用Firebase托管+ Cloud Run Express服务器时,在哪里设置Cache-Control?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!