Google HTML/CSS Style Guide が勉強になった

はてブホッテントリにあがってた

Google HTML/CSS Style Guide が良かったです。これそのまま業務プロジェクトのガイド、規約として適用できるよようなすてきなドキュメントでした。

読んでて勉強になったものもいくつかあったのでメモしておきます。

#JavaScript Style Guide もあるみたいなので読んでみよかな。JavaのStyle Guideもあればいいのになぁ。

プロトコル省略

General Style Rules > Protocol のところ。

Omit the protocol from embedded resources.
Omit the protocol portion (http:, https:) from URLs pointing to images and other media files, style sheets, and scripts unless the respective files are not available over both protocols.
Omitting the protocol—which makes the URL relative—prevents mixed content issues and results in minor file size savings.

こんな書き方できんのね。便利。

オプショナル・タグ

HTML Style Rules > Optional tags のところ。

Omit optional tags (optional).
For file size optimization and scannability purposes, consider omitting optional tags. The HTML5 specification defines what tags can be omitted.
(This approach may require a grace period to be established as a wider guideline as it is significantly different from what web developers are typically taught. For consistency and simplicity reasons it is best served omitting all optional tags, not just a selection.)

これはかなり衝撃でした。Optional Tagについてほとんど何もしらなかったので、特にhtml、head、bodyが省略可能なのに衝撃。 確かにこのへんのタグは書かなくても文脈上自明やな・・・。自明な文書構造セマンティクスは省略するシンタックスシュガー的記法。便利。

でも理解の浅い人が、文書構造を意識してない汚いHTMLを書く原因にもなりそう・・・。

この記事も面白かった。
HTML5でのタグの省略は結構考えられている件