SlideShare a Scribd company logo
Brush up your Coding
2013 Winter
SaCSS Special 4

Frontrend in Sapporo
@1000ch
Self introduction
http://github.com/1000ch
@1000ch
http://1000ch.net/
Web Developer at CyberAgent, Inc.
agenda
Conclusion
Demonstration
Tool Introduction
TOOL INTRODUCTION
…の前に
なぜブラッシュ
アップするのか?
REASON TO BRUSH UP
パフォーマンスの向上
メンテナンス性の維持
メンテナンス性の維持
そのコード誰が見ても
理解できますか?
明日、そのコードを
他人に説明できますか?
パフォーマンスの向上
最近のフロントエンド技術…
CSS3
SVG
Canvas
WebGL
WebStorage
IndexedDB
AudioElement
VideoElement
WebWorker
WebSocket
AppCache
フロントエンドで
できることが増えている
できることが増えている分
ボトルネックになりやすい
the Performance Golden Rule
http://www.stevesouders.com/blog/2012/02/10/the-performance-
golden-rule/
80-90% of the end-user
response time
is spent on the frontend.
Start there.
- Steve Souders
サイトパフォーマンスの大部分
をフロントエンドで改善出来る
LET’S BRUSH UP!
今回紹介するツールは3つ
HTML / CSS / JavaScript
HTMLInspector
Introducing HTML Inspector
http://philipwalton.com/articles/introducing-html-inspector/
HTML Inspector is a code
quality tool to help you
and your team write
better markup. It's written
in JavaScript and runs in
the browser, so testing
your HTML has never been
easier. - Philip Walton
WITH BROWSER...
$ npm install -g bower
$ bower install html-inspector
HTMLInspectorをダウンロードする
HTMLでロードし実行する
<script src="path/to/html-inspector.js"></script>
<script>HTMLInspector.inspect()</script>
WITH CLI...
$ npm install -g html-inspector
HTMLInspectorをインストールする
# execute url
$ htmlinspector http://1000ch.net/
!
# execute local file
$ htmlinspector index.html
HTMLInspectorを実行する
もっと手軽に使いたい…
ChromeのExtensionを作りました。
H:Inspector
Please search for Chrome Store!
CSSLint
CSSLINT.NET
http://csslint.net/
CSS Lint open sourced
http://www.stubbornella.org/content/2011/06/15/css-lint-open-
sourced/
CSSLINT Ultra Translation
https://gist.github.com/hail2u/1303613
WITH BROWSER...
Webサイトにアクセスする
CSSを貼り付けて実行する
WITH CLI...
$ npm install -g csslint
CSSLINTをインストールする
# execute csslint
$ csslint [options] [file or directory]
CSSLINTを実行する
JSHint
JSHINT.COM
http://jshint.com/
JSHINT Documentation
http://jshint.com/docs/
WITH BROWSER...
JavaScriptを貼り付けて実行する
Webサイトにアクセスする
WITH CLI...
$ npm install -g jslint
JSHINTをインストールする
# execute jshint
$ jshint [options] [file or directory]
JSHINTを実行する
毎回ブラウザ見たり
コマンド叩くのか…
いいえ、自動化出来ます。
GRUNT
http://gruntjs.com/
WHAT IS GRUNT?
Node.jsで動くタスクランナー
設定ファイルがJavaScript
共有に必要なのは2ファイル
Gruntはフロントエンドエンジニ
アにも扱いやすいツール
Gruntの概要と導入手順とメリット
http://1000ch.net/2012/12/08/ReconsideringGruntJs/
demonstration
http://github.com/1000ch/brushup-sample
CHECK HTML
! Failed rule "validate-attributes".
" The 'bgcolor' attribute is no longer valid on the <body>
element and should not be used.
HTMLは文書構造を定義、CSSは装飾やレイアウト
という切り分けを行いましょう。
! Failed rule "unused-classes".
" The class 'hoge' is used in the HTML but not found in any
stylesheet.
定義されていないCSSはHTMLで参照しないように
しましょう。CSSの参照コストが発生してしまい
ます。
! Failed rule "unnecessary-elements".
" Do not use <div> or <span> elements without any
attributes.
CSSの装飾や、属性値も持たない<div>や<span>
は必要ないはずです。深ければ深いほど、描画時
のリフローの回数が増え、CSSやJSの参照のコス
トが増えます。
! Failed rule "validate-attributes".
" The 'alt' attribute is required for <img> elements.
必須とされている属性値は記述するようにしま
しょう。ちなみに、<img>にはwidthとheightを
つけるのが望ましいです。そして、srcの値を空に
しないようにしましょう。
「src、hrefの値を空にしない。
モダンブラウザではほとんど解決されているが、
HTTPリクエストが発生してしまうブラウザがある。」
!
<img src="" >
<script src=""></script>
<link href="">
!
var img = new Image();
img.src = "";
!
Empty image src can destroy your site
http://www.nczonline.net/blog/2009/11/30/empty-image-src-can-
destroy-your-site/
! Failed rule "validate-elements".
" The <font> element is obsolete and should not be used.
<font>タグは非推奨です。前述の通り、HTMLは
文書構造の定義という役割になったためです。
<center>、<basefont>、<u>、<s>等にも同様の
ことが言えます。
HTML要素リファレンス
https://developer.mozilla.org/ja/docs/Web/HTML/Element
! Failed rule "inline-event-handlers".
" An 'onclick' attribute was found in the HTML. Use
external scripts for event binding instead.
イベントの定義はJSファイルで行うようにしま
しょう。インラインの定義は管理が非常に難しく、
予期しない不具合を引き起こします。
<button id="js-bar" onclick="alert('Clicked!')">
var btn = document.getElementById("js-bar");
btn.addEventListener("click", function() {
alert("Clicked!");
});
「JavaScriptはJSファイルに書きましょう。」
! Failed rule "script-placement".
" <script> elements should appear right before the closing
</body> tag for optimal performance.
<script>タグは同期的に実行されるため、その間
ページの描画が止まります。</body>の上に置く
ことでそれを極力避ける事ができます。
CHECK CSS
Values of 0 shouldn't have units specified. You don't need
to specify units when a value is 0. (zero-units)
0pxも0%も0であることに変わりはありません。
単位を削ってファイルサイズを減らしましょう。
Element (a.active) is overqualified, just use .active
without element name. Don't use classes or IDs with elements
(a.foo or a#foo). (overqualified-elements)
a.activeは不要に詳細度が増しているセレクタで
す。.activeとし、タグに依存しないようにしま
しょう。セレクタにIDを使用するのもやめましょ
う。
「コードそのものの量を抑え、パフォーマンスが向上し、
可搬性を向上させ、詳細度を減らすことができる。」
ul.nav li.active a {}
!
div.header a.logo img {}
!
.main ul.features a.btn {}
.nav .active a {}
!
.logo > img {}
!
.features-btn {}
Code smells in CSS
http://csswizardry.com/2012/11/code-smells-in-css/
The properties padding-top, padding-bottom, padding-left,
padding-right can be replaced by padding. Use shorthand
properties where possible. (shorthand)
ショートハンドで記述し、冗長な表現は避けましょ
う。
「margin、padding、まとめる。」
.foo {
margin-top: 10px;
margin-right: 20px;
margin-bottom: 10px;
margin-left: 20px;
}
!
.bar {
margin-top: 5px;
margin-left: 15px;
margin-bottom: 10px;
margin-right: 15px;
}
!
!
.foo {
margin: 10px 20px;
}
!
!
.bar {
margin: 5px 15px 10px;
}
!
!
@import prevents parallel downloads, use <link> instead.
Don't use @import, use <link> instead. (import)
さらに良いのは、CSSファイルをすべて結合して1
ファイルにすることです。Webパフォーマンスの
向上の第一歩はHTTPリクエストの数を減らす + ダ
ウンロードサイズを減らすことです。
Mobile Front-end

Optimization Standard:2012
https://speakerdeck.com/t32k/mobile-front-end-optimization-
standard-2012
CHECK Javascript
eval can be harmful.
eval()はパフォーマンスが悪い上に、スコープがわ
かりにくくセキュリティ的にも危ないです。eval()
を必要とするケースはほとんど無いはずです。
Missing semicolon.
処理の終わりには忘れずセミコロンを付けましょ
う。括弧も省略するべきではありません。省略す
ることで振る舞いが変わってしまう恐れがありま
す。
Use '!==' to compare with 'null'
nullとの比較に限らず、基本的に厳密等価演算子
を推奨します。キャストがない分高速である上、
暗黙の型変換は誤解を招きやすいです。
Equals Operator vs Strict Equals Operator
http://jsperf.com/equals-operator-vs-strict-equals-operator/2
The object literal notation {} is preferrable.
The array literal notation [] is preferrable.
new Array()による配列の初期化は、引数がわかり
にくいです。双方ともリテラルを使ったほうが完
結でわかりやすいです。
var array1 = new Array("foo"); // ["foo"]
!
var array2 = new Array("foo", "bar"); // ["foo", "bar"]
!
var array3 = new Array(3); // [] and array3.length is 3
var array1 = ["foo"]; // ["foo"]
!
var array2 = ["foo", "bar"]; // ["foo", "bar"]
!
var array3 = [undefined, undefined, undefined];
// [] and array3.length is 3
「Objectはもっとわかりにくいので割愛…。」
JavaScript Garden
http://bonsaiden.github.io/JavaScript-Garden/ja/
CONCLUSION
HTML
レイアウトや装飾はCSSにやってもらう
Scriptタグはページ下部に置く
HTML5で提唱される要素のキャッチアップ
CSS
Sass等を使う場合はコンパイル後を意識する
CSSは壊れやすい!
HTML構造に依存しないCSSを書く
JavaScript
書き方一つで実行速度が変わる
CSSで出来ることはCSSでやる
省略しない!JavaScriptは可読性が命
リファクタリングのフロー化
Jenkins、ローカル環境でのGrunt、Travis CI等。
The first draft of
anything is shit
- Ernest Hemingway
指摘される内容の理解
必ず理由があります。調べて理解して直す!
スキルアップに直結
踏まえてやれば間違いなく技術は向上します。
KEEP OPTIMIZING!
THANK YOU!
@1000ch
PHOTO CREDITS
• http://www.flickr.com/photos/fotuwe/6851855959/
• http://www.flickr.com/photos/88256536@N00/5420396616/
• http://www.flickr.com/photos/mckenzieo/2006687207/
• http://www.flickr.com/photos/gaetanlee/298680664/
• http://www.flickr.com/photos/64312248@N04/5969283186/
• http://www.flickr.com/photos/55027967@N07/5189465437/

More Related Content

PPTX
チュートリアルではじめるVue.js
PDF
Brush up your Coding!
PPTX
エンタープライズ分野での実践AngularJS
PDF
Vue.js入門
PDF
そろそろ押さえておきたい AngularJSのセキュリティ
PDF
プロダクトに 1 から Vue.js を導入した話
PPTX
ライオンでも分かるVuejs
PDF
KnockoutJS勉強会 プロジェクトにmvvmを適用する狙い
チュートリアルではじめるVue.js
Brush up your Coding!
エンタープライズ分野での実践AngularJS
Vue.js入門
そろそろ押さえておきたい AngularJSのセキュリティ
プロダクトに 1 から Vue.js を導入した話
ライオンでも分かるVuejs
KnockoutJS勉強会 プロジェクトにmvvmを適用する狙い

What's hot (20)

PPTX
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
PPTX
簡単AngularJS(関西AngularJS勉強会)
PDF
はじめてのVue.js
PPTX
AngularJSを浅めに紹介します
PDF
3分でわかるangular js
PPTX
Laravel Blade×vue.js 混在させる場合の注意点
PDF
AngularJSでの非同期処理の話
PPTX
20140517 knockoutjs hands-on
PPTX
Angular js はまりどころ
PDF
JavaEE7徹底入門 プレゼンテーション層の開発 JSF
PDF
AngularJSの高速化
PDF
Knockout.js を利用したインタラクティブ web アプリケーション開発
PDF
レスポンシブWebデザイン【発展編】
PDF
DevLOVE Kansai KnockoutJS
PDF
Vue.jsでさくっとMVVM
PPTX
AngularJS入門
PDF
React.jsでクライアントサイドなWebアプリ入門
PPTX
20160927 reactmeetup
PDF
受託開発でのAngularJS - 第1回AngularJS 勉強会 at LIG
PDF
AngularJSについて
クライアントサイドMVVMアーキテクチャとVue.jsをまとめたよ
簡単AngularJS(関西AngularJS勉強会)
はじめてのVue.js
AngularJSを浅めに紹介します
3分でわかるangular js
Laravel Blade×vue.js 混在させる場合の注意点
AngularJSでの非同期処理の話
20140517 knockoutjs hands-on
Angular js はまりどころ
JavaEE7徹底入門 プレゼンテーション層の開発 JSF
AngularJSの高速化
Knockout.js を利用したインタラクティブ web アプリケーション開発
レスポンシブWebデザイン【発展編】
DevLOVE Kansai KnockoutJS
Vue.jsでさくっとMVVM
AngularJS入門
React.jsでクライアントサイドなWebアプリ入門
20160927 reactmeetup
受託開発でのAngularJS - 第1回AngularJS 勉強会 at LIG
AngularJSについて
Ad

Similar to Brush up your Coding! 2013 winter (20)

PDF
jQuery Performance Tips – jQueryにおける高速化 -
PDF
2018年に於ける HTML の役割(実践編)
KEY
Webapp startup example_to_dolist
PDF
Firefox DevTools
PDF
フロント作業の効率化
PDF
「html5 boilerplate」から考える、これからのマークアップ
PDF
なんでCSSすぐ死んでしまうん
KEY
コーディングが上達するコツ
PDF
Web制作勉強会 #2
PDF
Visualforce + jQuery
PDF
プログラム組んだら負け!実はHTML/CSSだけでできること2015夏
PDF
WordBench Kobe jQueryどうでしょう
PDF
CoffeeScriptってなんぞ?
PDF
今からハジメるHTML5マークアップ
PDF
Chrome Developer Toolsを使いこなそう!
PDF
アイデアを形にする ②HTML/CSSから始めるWeb技術の基礎
PPT
アプリコンテスト
PDF
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
PPTX
CSS Nite in Matsuyama vol.1 - session 4
PDF
CSS Design and Programming
jQuery Performance Tips – jQueryにおける高速化 -
2018年に於ける HTML の役割(実践編)
Webapp startup example_to_dolist
Firefox DevTools
フロント作業の効率化
「html5 boilerplate」から考える、これからのマークアップ
なんでCSSすぐ死んでしまうん
コーディングが上達するコツ
Web制作勉強会 #2
Visualforce + jQuery
プログラム組んだら負け!実はHTML/CSSだけでできること2015夏
WordBench Kobe jQueryどうでしょう
CoffeeScriptってなんぞ?
今からハジメるHTML5マークアップ
Chrome Developer Toolsを使いこなそう!
アイデアを形にする ②HTML/CSSから始めるWeb技術の基礎
アプリコンテスト
Featuring Project Silk & Liike: 楽しい "モダン" Web 開発のちょっとディープなお話
CSS Nite in Matsuyama vol.1 - session 4
CSS Design and Programming
Ad

More from Shogo Sensui (16)

PDF
Web Standards Interop 2022
PDF
Introduction to Performance APIs
PDF
Web Standards 2018
PDF
The State of Web Components
PDF
Component of Web Frontend
PDF
Web フロントエンドの変遷とこれから
PDF
Introduction to Resource Hints
PDF
Web Components 2016 & Polymer v2
PDF
これからのJavaScriptの話
PDF
初心者のためのWeb標準技術
PDF
Introduction to Service Worker
PDF
We should optimize images
PDF
Web Components changes Web Development
PDF
Re-think about Web Performance
PDF
Browser Computing Structure
PDF
Functional JavaScript with Lo-Dash.js
Web Standards Interop 2022
Introduction to Performance APIs
Web Standards 2018
The State of Web Components
Component of Web Frontend
Web フロントエンドの変遷とこれから
Introduction to Resource Hints
Web Components 2016 & Polymer v2
これからのJavaScriptの話
初心者のためのWeb標準技術
Introduction to Service Worker
We should optimize images
Web Components changes Web Development
Re-think about Web Performance
Browser Computing Structure
Functional JavaScript with Lo-Dash.js

Brush up your Coding! 2013 winter