ArticleDirectory
Google today released the HTML/CSS code Style Guide (Google html/CSS style guide). In fact, this is not a complete set of development specifications. We can think of it as a simple development suggestion.
Like Google JavaScript style guide I mentioned in "using Google closure Linter to verify JavaScript code", this document can only contain a small amount of content, and I have finished reading it in less than an hour, from this shortCodeThe Style Guide finds some interesting content. I will list two items below.
Resource file omitted Protocol
We recommend that you omit the protocol section in images, media files, styles, and script URLs (HTTP:
,Https:
). After the protocol is omitted, the resource file inherits the protocol of the page url. this not only prevents mixed content, but also reduces the page size. for example, you can reference a Javascript file in the following recommended method.
Omit optional labels
Those who have used dreamwave should be impressed. When you create an HTML file, the default code is as follows.
<HTML>
We willTitle
, External CSS and JavaScript references are placed inHead
Area where the content displayed on the page is placedBody
But in factHtml
,Head
AndBody
All labels can be omitted.
After deleting these optional tags, it looks strange, but the page is displayed normally, and W3C detection can also pass. I have already done this on my blog. note that if you want to write pages in XHTML, keepHtml
Tag, because you still need the following code as a declaration.
<HTML xmlns = "http://www.w3.org/1999/xhtml">
Remarks
Google's HTML/CSS code style guide is a short and concise manual for coding the builders. It is useful, but do not be superstitious. for example, if there is one item in it, we suggest using two spaces as indentation. In many teams, it may not be feasible. Now our team uses tab.
Many HTML recommendations in this manual are for HTML5, but here the HTML style is used instead of the XHTML style. In many cases, code readability is actually impaired to omit the code, you should judge the trade-off.