Azure CDN - 启用 HTTP 压缩 - 托管 Web 角色 [英] Azure CDN - Enabling HTTP Compression - Hosted Web Role

查看:25
本文介绍了Azure CDN - 启用 HTTP 压缩 - 托管 Web 角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人成功过使用托管 Web 角色为 HTTP 压缩配置 Azure CDN?我们在 Azure 边缘服务器上压缩 HTTP 内容时遇到问题.CDN 只缓存内容的未压缩版本.

如果我们通过非 Azure 方法点击我们的资源链接 (webresource.axd),它会通过 gzip(使用 xxxx.cloudapp.net/cdn/webresource.axdem>) 正如预期的那样.但是,一旦我们将资源链接指向 Azure CDN (xxxx.vo.msecnd.net),尽管浏览器告诉 Azure CDN 它接受 gzip,内容仍会以未压缩的形式提供.>

发布了同样的内容向 Azure 论坛提出问题,但至今无人回应.

在对问题进行故障排除时,Azure CDN 似乎正在去除 Accept-Encoding HTTP 标头.只是好奇其他人是否也遇到过同样的问题.

Azure CDN 最佳实践声明...

<块引用>

Windows Azure CDN 如何处理压缩内容?

Windows Azure CDN 不会修改(或添加)对您的对象的压缩.Windows Azure CDN 尊重源基于接受编码"提供的任何压缩.标题.从 1.4 开始,Azure 存储不支持压缩.如果您使用托管服务对象传递,您可以配置 IIS 以返回压缩对象.

我们看到的是 CDN 不尊重源接受编码,它被剥离了.

解决方案

通过反复试验发现,Azure CDN 当前存在一个限制,即它不会通过 Accept-Encoding HTTP 标头除非它找到包含可压缩文件名类型(.js、.cs)的 QueryString 参数,或者您正在请求文件的原始名称(jquery.js、site.css 等)).

这意味着如果您使用 AXD 资源处理程序(WebResource.axd 等),则不会进行 HTTP 压缩.如果您附加带有 .cs.js 扩展名的 QueryString 参数,Azure CDN 只会传递 Accept-Encoding.

我们正在使用自定义 AXD 资源处理程序,因此这对我们来说很容易实现.我们刚刚将 &group=core.js&group=core.css 应用到我们组合的最小化资源中,并且压缩按预期工作.很遗憾,当前的 Azure CDN 文档.

简而言之,我们必须从这里转换我们的 URI:

<块引用>

https://xxxx.vo.msecnd.net/resourceManager.axd?token=HL80vX5hf3lIAAA

为此:

<块引用>

https://xxxx.vo.msecnd.net/resourceManager.axd?token=HL80vX5hf3lIAAA&group=core.js

一旦 Azure CDN 在查询字符串中看到 .js,它将返回资源的压缩版本.

希望这对使用通过 Azure CDN 提供的 Web 资源 (AXD) 的其他人有所帮助.

Has anyone successfully configured Azure CDN for HTTP compression using their hosted web role? We are having trouble compressing HTTP content at the Azure edge servers. The CDN is only caching the uncompressed version of the content.

If we hit our resource link (webresource.axd) from a non-Azure approach it compresses via gzip (using the xxxx.cloudapp.net/cdn/webresource.axd) as expected. However, as soon as we point our resource link to Azure CDN (xxxx.vo.msecnd.net), the content is served up uncompressed, despite the browser telling the Azure CDN it accepts gzip.

I posted this same issue to Azure Forums, but nobody has responded as of yet.

While troubleshooting the problem, it appears that the Azure CDN is stripping out the Accept-Encoding HTTP header. Just curious if others have had this same issue.

Azure CDN Best Practices states...

How does the Windows Azure CDN work with compressed content?

The Windows Azure CDN will not modify (or add) compression to your objects. The Windows Azure CDN respects whatever compression is provided by the origin based on the "Accept-Encoding" header. As of 1.4, Azure Storage does not support compression. If you are using hosted-service object delivery, you can configure IIS to return compressed objects.

What we are seeing is that the CDN is not respecting the origin Accept-Encoding, it's being stripped away.

解决方案

It was discovered thru trial and error that Azure CDN has a current limitation that it won't pass the Accept-Encoding HTTP header unless it finds a QueryString parameter containing a compressable filename type (.js, .cs) or you are requesting a file by its original name (jquery.js, site.css, etc.).

What this means is that if you are using an AXD resource handler (WebResource.axd, etc.), the HTTP compression will not be performed. The Azure CDN will only pass the Accept-Encoding if you append a QueryString parameter with a .cs or .js extension.

We are using a custom AXD resource handler, so this was easy for us to implement. We just applied &group=core.js and &group=core.css for our combined minified resources and the compression worked as expected. It's unfortunate this doesn't exist in the current Azure CDN documentation.

In short, we had to transform our URIs from this:

https://xxxx.vo.msecnd.net/resourceManager.axd?token=HL80vX5hf3lIAAA

to this:

https://xxxx.vo.msecnd.net/resourceManager.axd?token=HL80vX5hf3lIAAA&group=core.js

Once the Azure CDN sees the .js in the querystring, it will return the compressed version of the resource.

Hope this helps someone else using web resources (AXDs) served up via the Azure CDN.

这篇关于Azure CDN - 启用 HTTP 压缩 - 托管 Web 角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆