我有一个用 Firebase 编写的 Web 应用程序,并将其部署到 Firebase 托管。 在网络应用程序中,我调用一个云函数,它返回某种静态数据(数据在一两天内发生变化)。 是否可以绕过云函数调用执行并直接通过 Firebase 全局 CDN 提供服务。 这是我已经在 firebase json 中尝试过的。
{
"hosting": {
"target": "flutter",
"public": "build/web",
"headers": [
{
"source": "**",
"headers": [
{
"key": "Cache-Control",
"value": "'public, max-age=300, s-maxage=600'"
}
]
}
],
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
},
{
"source": "/getData/**",
"destination": "/index.html"
},
{
"source": "https://us-central1-xxxxx.cloudfunctions.net/getData",
"destination": "/index.html"
}
]
}
}
提前致谢
您应该查看 有关管理 Firebase 托管的缓存行为的文档。
您的函数需要设置一个缓存控制标头来指示其响应应缓存多长时间。如果这样做,则 Firebase 托管将提供缓存的响应,直到指定的过期时间。
res.set('Cache-Control', 'public, max-age=300, s-maxage=600');