开发者

Why does Facebook have a #! in the URL in Firefox but non in Chrome?

开发者 https://www.devze.com 2023-01-25 10:09 出处:网络
In Safari, Firefox: www.facebook.com/#!/home.php?sk=updates In Chrome: www.facebook.com/home.php?sk=开发者_开发知识库updates

In Safari, Firefox:

www.facebook.com/#!/home.php?sk=updates

In Chrome:

www.facebook.com/home.php?sk=开发者_开发知识库updates

...without #!.

What's the trick?


It's a way to tell Google (and others) that this is AJAX content. I think it is called a shebang. ! by itself is often referred to as the bang character.

If you're running an AJAX application with content that you'd like to appear in search results, we have a new process that, when implemented, can help Google (and potentially other search engines) crawl and index your content

Source.

The hash also allows the back button, bookmarking, etc to work as desired in a AJAXy application.

As for the difference, I think it just means you followed a hard link on one, and an Ajax link on the other.


It's likely that AJAX is extensively used for the first URL, while the second URL does not use AJAX to load important content (instead using conventional web page loading). Roughly speaking, by AJAX I mean that JavaScript code is used to load new sections into the page without reloading it entirely, leading to a "smoother" user experience.

Two URLs differing only in what is after the # are actually on the same page (but can be almost like separate pages in terms of navigation), as JavaScript code can insert one of these "hashes" into the back/forward/reload history of the web browser when a user clicks on a "link" (or bookmarks the page). It can also detect when the user clicks the back button by monitoring what is known as onhashchange, loading the correct page accordingly.

Note that since this is the same HTML page, the part of the URL after the # (called the "fragment identifier" by official specs) is not sent to the server until the application's JavaScript code makes the AJAX request.

Why is it #! instead of just # though? The former is what Google has recently pushed to improve accessibility of such pages to search engines, which do not completely support JavaScript (or not at all). It is how if someone uses such a link in a web page, Google's crawler can follow it, because it recognizes the character sequence and rewrites the URL in a standardized manner (so the server gets all necessary information to send the page to the crawler without using AJAX).


The #! is used to make the site work on AJAX while still allowing use of browser's Back, Forward and Refresh buttons. If it's not there, then the currently viewed page hasn't been brought in by AJAX, simple as.

0

精彩评论

暂无评论...
验证码 换一张
取 消