javascript - How does Google hide HTML source of search results? - Stack Overflow

When you try to view the source code of a Google search results page you just see a bunch of javascript

When you try to view the source code of a Google search results page you just see a bunch of javascript code instead of readable text. How does Google do that?

I have searched through the web but couldn't find a good explanation, only thing I found was this: and it is not really helpful.

I am not a web developer but I just got curious. A brief explanation would be nice. Thanks.

When you try to view the source code of a Google search results page you just see a bunch of javascript code instead of readable text. How does Google do that?

I have searched through the web but couldn't find a good explanation, only thing I found was this: http://goo.gl/FIvD6 and it is not really helpful.

I am not a web developer but I just got curious. A brief explanation would be nice. Thanks.

Share Improve this question asked Apr 18, 2013 at 9:14 C.d.C.d. 10k7 gold badges42 silver badges52 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1

Google builds the DOM with the javascript you noted. It does this for a number of reasons:

  • Decrease the load on the server to generate each dynamic result set with HTML markup.
  • Google returns the results in a JSON feed (example) - pastebin. Less processing power is required to produce the JSON response than a full HTML snippet or pletely new page
  • Speed. Assuming that the user has a decent internet connection, the speed of the pages rendering on the client side pared to the server side is negligible.

As suggested above, jump into firebug and have a look around :)

Google does that by generating the page using a pile of client side JavaScript. It's almost certainly a side effect, not a design goal.

Google loads additional elements via Ajax, so you won't get them if you view the source. You can use something like Firebug to check the DOM elements after you make a new query.

That link actually explains it quite clearly. The real point is, Google isn't "hiding" anything. There is an extra layer to all of this, which is called the DOM (Document Object Model). When a page is requested from a web server, the web server might respond with some basic HTML and a lot of JavaScript code. This response is then interpreted by your browser. It will load the HTML elements into the DOM, and then get started on churning through all of the JavaScript code, this JavaScript usually consists of a lot of instructions which manipulate the DOM (the in-memory representation of the page). It might load some extra data and insert new bits and pieces to display. The "browser window" if you like, renders whatever is in the DOM. Which is not necessarily the same as whatever is in the original request, because of all the instructions that have run even before the page is rendered inside your "browser window".

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744847872a4596952.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信