我在 firebug 中查看 google.com 的网络活动只是因为我很好奇并注意到一个请求返回204 No Content".
I was looking into google.com's Net activity in firebug just because I was curious and noticed a request was returning "204 No Content."
事实证明,204 No Content"的主要目的是允许输入进行操作,而不会导致用户代理的活动文档视图发生变化,尽管任何新的或更新的元信息都应该应用于当前在用户代理的活动视图."随便.
It turns out that a 204 No Content "is primarily intended to allow input for actions to take place without causing a change to the user agent's active document view, although any new or updated metainformation SHOULD be applied to the document currently in the user agent's active view." Whatever.
我查看了 JS 源代码,发现generate_204"是这样请求的:
I've looked into the JS source code and saw that "generate_204" is requested like this:
(new Image).src="http://clients1.google.com/generate_204"
根本没有变量声明/赋值.
No variable declaration/assignment at all.
我的第一个想法是它被用来跟踪是否启用了 Javascript.但是无论如何,(new Image).src='...'"调用是从动态加载的外部 JS 文件中调用的,所以这毫无意义.
My first idea is that it was being used to track if Javascript is enabled. But the "(new Image).src='...'" call is called from a dynamically loaded external JS file anyway, so that would be pointless.
有人对这点可能有任何想法吗?
Anyone have any ideas as to what the point could be?
更新
/generate_204"似乎可用于许多 google 服务/服务器(例如 maps.google.com/generate_204、maps.gstatic.com/generate_204 等...).
"/generate_204" appears to be available on many google services/servers (e.g., maps.google.com/generate_204, maps.gstatic.com/generate_204, etc...).
您可以通过为您的网络应用可能使用的每个 google 拥有的服务预先获取 generate_204 页面来利用这一点.像这样:
You can take advantage of this by pre-fetching the generate_204 pages for each google-owned service your web app may use. Like This:
window.onload = function(){
var two_o_fours = [
// google maps domain ...
"http://maps.google.com/generate_204",
// google maps images domains ...
"http://mt0.google.com/generate_204",
"http://mt1.google.com/generate_204",
"http://mt2.google.com/generate_204",
"http://mt3.google.com/generate_204",
// you can add your own 204 page for your subdomains too!
"http://sub.domain.com/generate_204"
];
for(var i = 0, l = two_o_fours.length; i < l; ++i){
(new Image).src = two_o_fours[i];
}
};
就像 Snukker 所说,clients1.google.com 是搜索建议的来源.我的猜测是,他们会在您需要之前发出请求以强制 clients1.google.com 进入您的 DNS 缓存,因此您在第一个真实"请求时的延迟会更短.
Like Snukker said, clients1.google.com is where the search suggestions come from. My guess is that they make a request to force clients1.google.com into your DNS cache before you need it, so you will have less latency on the first "real" request.
谷歌浏览器已经对页面上的任何链接执行此操作,并且(我认为)当您在地址栏中键入地址时.这似乎是一种让所有浏览器都做同样事情的方法.
Google Chrome already does that for any links on a page, and (I think) when you type an address in the location bar. This seems like a way to get all browsers to do the same thing.
这篇关于Google.com 和 clients1.google.com/generate_204的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!