【问题标题】:serving gzipped files on Firebase Hosting在 Firebase 托管上提供 gzip 文件
【发布时间】: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

有什么想法吗?

【问题讨论】:

    标签: firebase-hosting


    【解决方案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
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-18
    • 1970-01-01
    • 2020-06-17
    • 2018-07-11
    • 2017-11-24
    相关资源
    最近更新 更多