Table of Contents
回复内容:
Home Web Front-end H5 Tutorial Google 的 HTML 代码看着很乱,为什么要写成这样呢?

Google 的 HTML 代码看着很乱,为什么要写成这样呢?

Jun 07, 2016 am 08:42 AM
html

他的html代码用了什么不常用的技术..

回复内容:

我们在编写代码的时候常常用了很多空格或者缩进,这样一眼就能看出大概写什么,比如html在最左端,head和body往右边缩进一点,if,div什么的相对与head或body也向右边缩进一点。

这主要是为了给人看,但是多了这么多空格,可读性是增加了,可是页面的大小却大了。

如果压缩掉,原先10K的可能变成6K,那么就节省了4K,100个用户原先要下载1000K的,现在只要600K,流量就节省了400K,GOOGLE浏览量那么大,1000万用户呢?一亿用户呢?这样可以节约流量。
反正99%的人没事不会去看google的源码,可读性不重要,google内部是有带了空格的可读性好的版本,如果想改代码,改完了再压缩,才放上去。还有的看起来比较乱不是html也不是javascript等语言的,那么肯定就是加密过了的。跟乱码似的,但是浏览器还是能读出来

=== 下面内容更新于 2014-12-12 ===

Why does Google use inline JavaScript and CSS on its homepage?
这个同样也是为了节省请求次数,加快速度,节省流量。【Quora】 基本的道理,郑诚的回答已经很清楚了

对于想更深入了解的,可以参考一下雅虎的前端优化XX条(记得最开始看的时候还是14条,现在已经34条了,天……)

对于已经看过这些原则,早已了然于胸的,我再补点料。
google首页可能是有史以来pv最高的页面,其优化也比较极端,极端到以下两种做法我在别的网站从来没见到过(我没有详细考证google的其他页面是否也有这样的处理):

1. 在服务器端处理跨浏览器兼容,根据User-Agent返回不同的页面内容
对于跨浏览器兼容,传统的做法包括:用js判断浏览器类型做不同处理、使用css hack、浏览器私有标记/属性。总而言之,在浏览器端搞定兼容性。
但这并不是唯一的解决方案,更不是对用户最优的。如果能承受工作量,可以做到在服务器端处理,则兼容性相关的代码不必传给用户,可以节省相关的网络流量。而google首页就是这样做的。
可以给firefox装个ua switcher,一试便知。

我觉得,大多数网站,可能没有这种页面简单,而又pv巨巨高的页面来玩这套。但将工作量向服务器端转移,可以成为一种思路,比如jquery库中,很多代码在处理特定浏览器中的问题,那不妨分浏览器编译出若干版本,在体积和执行效率上都有优势。

2. 为减小页面体积,不惜违背规范
这个要只是属性不写双引号之类的,也就不拿出来说事了。
但你打开google首页,找不到
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles