在 Firebase 托管上提供 gzip 文件

Posted

技术标签:

【中文标题】在 Firebase 托管上提供 gzip 文件【英文标题】:serving gzipped files on Firebase Hosting 【发布时间】:2016-03-22 23:18:32 【问题描述】:

我对使用 Firebase 托管服务 gzipped html/css/js 文件很感兴趣。我尝试在 firebase.json 中设置 Content-Encoding 标头,但在部署时出错。

据称,您可以设置的唯一标头包括:Cache-Control、Access-Control-Allow-Origin、X-UA-Compatible、X-Content-Type-Options、X-Frame-Options、X-XSS-Protection

有什么想法吗?

【问题讨论】:

【参考方案1】:

默认情况下,Firebase 托管已对您的所有文件进行 gzip 压缩。例如,这里是我在 firebase 上托管的 css 文件的响应标头。注意Content-Encoding 标头:

Accept-Ranges:bytes
Cache-Control:max-age=7178000
Connection:keep-alive
Content-Encoding:gzip
Content-Length:3483
Content-Type:text/css; charset=utf-8
Date:Sun, 10 Jan 2016 02:09:57 GMT
ETag:"4c94283e07340e9cc0237fc2a349c94d"
Last-Modified:Sun, 10 Jan 2016 00:10:31 GMT
Server:nginx
Strict-Transport-Security:max-age=31556926; includeSubDomains; preload
Vary:Accept-Encoding
Via:1.1 varnish
X-Cache:HIT
X-Cache-Hits:1
X-Powered-By:Express
X-Served-By:cache-lax1432-LAX

【讨论】:

好吧,看起来确实如此。现在我需要弄清楚为什么我的请求没有给出 Accepts-Encoding 标头。谢谢塞巴斯蒂安! 我不知道是否发生了变化,但我的 css 文件返回了以下内容,没有内容编码:Accept-Ranges:bytes Cache-Control:max-age=31536000 Connection:keep-alive Content-Length:3360 Content-Type:text/css; charset=utf-8 Date:Thu, 15 Sep 2016 00:56:13 GMT ETag:"83bab03bd7b4d7f01f03858b2c1e58a2" Last-Modified:Wed, 14 Sep 2016 07:08:13 GMT Server:nginx Strict-Transport-Security:max-age=31556926; includeSubDomains; preload Vary:Accept-Encoding Via:1.1 varnish X-Cache:HIT X-Cache-Hits:1 X-Powered-By:Express X-Served-By:cache-sjc3135-SJC 即使我的请求标头包含Accept:text/css,*/*;q=0.1 Accept-Encoding:gzip, deflate, sdch, br

以上是关于在 Firebase 托管上提供 gzip 文件的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 React 和 Firebase 托管在 SPA 上提供 robots.txt?

带有 webpack 的 Vue.js 不提供压缩的 GZIP .js 文件

如何在 Firebase 托管上部署 next.js 应用程序?

如何使用 Firebase 托管来托管图像?

如何在 firebase 托管中托管单页 webapp 的静态文件,并将 web API 部署在不同的服务器中

googleapis导入失败,带有typescript / vue / firebase托管