从XMLHtt prequest删除HTTP头 [英] Removing HTTP headers from an XMLHttpRequest

查看:524
本文介绍了从XMLHtt prequest删除HTTP头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的AJAX长轮询类型的应用程序,我想尽量减少带宽我使用量。其中一个很大的成本,现在是客户端的HTTP标头。有一次,我已经建立了连接,并存储在客户端的会话ID,我真的不希望浪费更多的带宽传输冗余HTTP信息(如浏览器类型,接受编码等)。在许多连接的过程中,这种迅速加起来大量的数据!

I am working on an ajax long polling type application, and I would like to minimize the amount of bandwidth I am using. One of the big costs right now are the client side HTTP headers. Once I have a connection established and a session id stored on the client, I don't really want to squander any more bandwidth transferring redundant http information (such as browser type, accept encodings, etc.). Over the course of many connections, this quickly adds up to a lot of data!

我真的想只是把我XMLHtt prequest及核武器攻击的所有报头,使得只有最低限度被发送到服务器。是否有可能做到这一点?

I would really like to just take my XMLHttpRequest and nuke all of the headers so that only the absolute minimum gets transmitted to the server. Is it possible to do this?

推荐答案

您已经很难控制请求头,但你仍然可以做几件事情 -

You have very little control over request headers, but you can still do a few things -

  1. 降低cookie的大小。一般情况下,你只需要会话ID,其他一切都可以被消除,存储服务器端。
  2. 将保持短网址尽量减少HTTP引用。时间越长你的页面的网址,更多的数据将通过HTTP引用发送。一个技巧就是将数据存储在片段标识符(URL中在#后的部分)。片段标识符永远不会被发送到服务器,让你在那边节省几个字节。
  3. 在一些请求头只,如果你有previous设置相应的响应头发送。例如,您可以间接控制的ETag,如果-modified-因为请求头的。
  1. Reduce the size of the cookie. In general, you only want the session id, everything else can be eliminated and stored server side.
  2. Minimize http referrer by keeping a short URL. The longer your page url, the more data will have to be sent via the http referrer. One trick is to store data in the fragment identifier (the portion of the url after the #). The fragment identifier is never sent to the server, so you save a few bytes over there.
  3. Some request headers are only sent if you had previous set corresponding response headers. For example, you can indirectly control the ETag and if-modified-since request headers.

您可能要考虑网络套接字支持为pretty的好(IE10 +)。

这篇关于从XMLHtt prequest删除HTTP头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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