包含未由 Google 服务器编码的预压缩 Brotli 的 HTML 文件

发布于 2025-01-15 05:33:55 字数 831 浏览 7 评论 0原文

我在 Google 云上托管一个单页静态网站,并尝试在我的 index.html 文件上实现文本压缩。

到目前为止,我所做的就是从 index.html 复制所有缩小的 html 代码,并使用 在线转换器,然后将 Brotli 代码以 index2.html 形式保存在我的存储桶中。最后,我将 index2.htmlContent-encoding 元值设置为 br

然而,尽管我期望如此,当我访问 www.mysite.com/index2.html 地址时,我只在 Chrome 中看到一个空白页面,在 Firefox 中看到“内容编码错误”。

我还使用 gzip 压缩执行了相同的过程,并将 content-encoding 设置为 gzip,但结果是相同的。我使用了 Google 的以下说明,但它似乎不是很全面。

我做错了什么?

PS 我正在使用带有有效 SSL 的 HTTPS。我还在浏览器中进行了检查,服务器发送了一个标头,其中在 content-encoding 字段中包含 gzip 和 br。

I'm hosting a single page static website on Google cloud and I'm trying to implement text-compression on my index.html file.

What I've done so far was to copy all my minified html code from index.html and convert it to Brotli code using an online converter and then saving the Brotli code as index2.html in my bucket. Finally I set the Content-encoding meta value of index2.html to br.

How ever, despite my expectation, I only see a blank page in Chrome and "Content Encoding Error" in Firefox when i go to the www.mysite.com/index2.html address.

I also did the same procedure with gzip compression and setting the content-encoding to gzip but the results were the same. I used the following instructions by Google but it doesn't seem very comprehensive.

What am I doing wrong?

P.S. I am using HTTPS with a valid SSL. I also ckecked in my browser, and the server sent a header that includes the gzip and br in the content-encoding field.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心安伴我暖 2025-01-22 05:33:55

它几乎(!)对我有用,但不是我期望的那样,我不清楚为什么。

我在托管网站的存储桶中有一个 (JPEG) 文件 ${IMAGE}

  1. 将图像复制到本地
  2. brotli
  3. brotli 的图像复制回存储桶
  4. 设置其元数据
  5. 浏览它。
gsutil cp gs://${BUCKET}/images/${IMAGE} ${PWD}

brotli ${IMAGE} --output=brotli.jpg

gsutil cp brotli.jpg gs://${BUCKET}/images

gsutil setmeta \
  -h "Content-Type:image/jpeg" \
  -h "Content-Encoding:br" \
  gs://${BUCKET}/images/brotli.jpg

gsutil stat gs://${BUCKET}/images/brotli.jpg 
    Content-Encoding:       br
    Content-Type:           image/jpeg

如果我直接在 Chrome 中浏览该网站,它会失败(取消),没有响应代码:

ERR_CONTENT_DECODING_FAILED

如果我浏览 GCS 公共 URL,它会工作 (200):

https://storage.googleapis.com/${BUCKET}/images/brotli.jpg

以及:

https://storage.cloud.google.com/${BUCKET}/images/brotli.jpg

如果我使用gzip 而不是 brotli,两者都按预期工作。

由于某种原因,我无法浏览作为静态站点一部分的 brotli 压缩文件,即使它确实存在并且我可以通过其他方式浏览 URL。

It almost (!) works for me but not how I expect it to and I'm unclear why.

I have a (JPEG) file ${IMAGE} in a bucket that's hosting a website.

  1. Copy the image locally
  2. brotli it
  3. Copy the brotli'd image back to the bucket
  4. Set its metadata
  5. Browse it.
gsutil cp gs://${BUCKET}/images/${IMAGE} ${PWD}

brotli ${IMAGE} --output=brotli.jpg

gsutil cp brotli.jpg gs://${BUCKET}/images

gsutil setmeta \
  -h "Content-Type:image/jpeg" \
  -h "Content-Encoding:br" \
  gs://${BUCKET}/images/brotli.jpg

gsutil stat gs://${BUCKET}/images/brotli.jpg 
    Content-Encoding:       br
    Content-Type:           image/jpeg

If I browse the site directly in Chrome, it fails (canceled) no response code:

ERR_CONTENT_DECODING_FAILED

If I browse the GCS public URL, it works (200):

https://storage.googleapis.com/${BUCKET}/images/brotli.jpg

And:

https://storage.cloud.google.com/${BUCKET}/images/brotli.jpg

If I use gzip rather than brotli, both work as expected.

For some reason, I'm unable to browse a brotli compressed file as part of the static site even though it's definitively present and I can browse the URL via other means.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文