CSSμ½λλ₯Ό ν¨μ¨μ μ΄κ³ μ΅μ ννλ©΄μ νμΌμ¬μ΄μ¦λ₯Ό μ€μΌ μ μλ CSSμ΅μ ν λ°©λ²μ λν΄μ μκΈ°λ₯Ό νλ €κ³ νλ€.
- μκ°
λμ± λ 볡μ‘ν CSSμ½λλ₯Ό μ°κ² λλ©΄μ μ΄λ¬ν κΈ°μ μ CSSνμΌ μ¬μ΄μ¦λ₯Ό λ¨μ§ λͺkilobytesλΌλ
μ€μ¬μΌν κ²μ΄λ€.
1. CSS Spriteμ μ¬μ©
"CSS Spriteλ image requestμ μμ²μ κ°μμν€λ λ°©λ²μ΄λ€. μ¬λ¬μ΄λ―Έμ§λ€μ νλμ μ΄λ―Έμ§λ‘
ν©μΉκ³ CSS background-image νΉμ background-positionμμ±μ μ΄μ©νμ¬ μ΄λ―Έμ§μ λΆλΆλ€μ
νλ₯νκ² λ³΄μ¬μ€λ€. - Yahoo Deloper Rule(http://developer.yahoo.com/performance/rules.html)
μ΄λ¬ν λ°©λ²μ HTTP Requestμ μΉμ¬μ΄νΈμ νΈλν½μ ν¨μ¨μ μΌλ‘ μ€μ¬μ€λ€.
CSS Sprtie μ°Έκ³
- A List Aprt - CSS Sprite (http://www.alistapart.com/articles/sprites)
- Azamsharp - Combining Images, CSS Sprites to Increase Performance (http://azamsharp.com/Posts/216_Combining_Images_CSS_Sprites_to_Increase_Performance.aspx)
2. λͺ¨λ CSSνμΌμ νλμ νμΌλ‘ ν©μ³λΌ
μ¬μ©μλ€μ΄ μΉμ¬μ΄νΈλ₯Ό μ μν λ νμ΄μ§μ λͺ¨λ κ°μ²΄(μ΄λ―Έμ§ λλ μ€ν¬λ¦½νΈ)λ₯Ό μλ²μ μμ²νκ²λλ€.
λΉμ μ΄ λͺκ°μ κ°μ²΄λ€μ λ€μ μ½μ΄ λ€μΈλ€λ©΄ νμ΄μ§μ μ§μ°μ λμ± κ°μ€ μν¬ κ²μ΄κ³ ,
μ΄λ¬ν HTTP Requestλ€μ λΉμ μ¬μ΄νΈμ μλ΅μκ°μ λ리κ²ν κ²μ΄λ€.
μ΄ κΈ°μ μ CSS Spriteμ μ μ¬νλ€. (μ΅μν λͺ©νλ κ°λ€) HTTP Requestλ₯Ό κ°μμν€λ κ²μ΄λ€.
3κ°μ CSSνμΌμ λ‘λ©νκ³ μλ€λ©΄ λΈλΌμ°μ λ 3κ°μ HTTP Requestμ μμ²μ 보λΈλ€. κ°λ¨νκ²
μνμ μΌλ‘ 1κ°μ CSS File = 1κ°μ HTTP ReuqestμΈ κ²μ΄λ€. λλ μΌλ°μ μΈ μΉμ¬μ΄νΈμμ
6~7κ°μ CSSνμΌμ Headerμμ μ¬μ©νλ€. μμ λ°©λ²μ μ¬μ©νλ€λ©΄ λ‘λ©μκ°μ λμ± ν¨μ¨μ μΌλ‘
λ§λ€μ΄ μ€ κ²μ΄λ€.
- Before
<link rel="stylesheet" type="text/css" href="content.css" />
<link rel="stylesheet" type="text/css" href="about.css" />
<link rel="stylesheet" type="text/css" href="contact.css" />
- After
<link rel="stylesheet" type="text/css" href="layout.css" />
3. μΈλΆνμΌ(external file)λ‘ CSSλ₯Ό λ§λ€μ΄λΌ
μΈλΆνμΌ(external file)μ μ¬μ©νλ©΄ CSS νμΌλ€μ΄ λΈλΌμ°μ Έμ μνμ¬ μΊμλμ΄μ Έ
λ λΉ λ₯Έ νμ΄μ§λ₯Ό λ§λ€ μ μλ€. CSSλ₯Ό νμ΄μ§λ΄ inlineμΌλ‘ μ¬μ©νκ² λλ©΄ 맀λ²
HTMLμ μμ²ν λ λ§λ€ λ€μ΄λμ΄ μ§λ€. μ΄λ¬ν HTTP requestλ₯Ό μ€μ΄κΈ° μν΄μλ
μΈλΆνμΌ(external file)μ μ¬μ©νλ©΄ λλ€. νμ§λ§ HTMLμ ν¬κΈ°λ λλκ² λλ€.
κ·Έλ¬λ external file(css)κ° λΈλΌμ°μ μ μν΄ μΊμλμ΄μ§λ©΄, HTML λ¬Έμμ
ν¬κΈ°λ 컀μ§μ§λ§ HTTP Requestμ μμ²μ μ€μ΄λ€κ²μ΄λ€.
- yahoo (http://developer.yahoo.net/blog/archives/2007/07/rule_8_make_jav.html)
μΈλΆ μλ°μ€ν¬λ¦½νΈ λλ cssνμΌμ λμ μΌλ‘ λ‘λ©νλ λ²
- μ ν΅μ μΈ λ°©λ²
<head>
<script type="text/javascript" src="myscript.js"></script>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
- DOM Methodλ₯Ό μ΄μ©νμ¬ μμ±νλ λ²
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
loadjscssfile("myscript.js", "js") //dynamically load and add this .js file
loadjscssfile("javascript.php", "js") //dynamically load "javascript.php" as a JavaScript file
loadjscssfile("mystyle.css", "css") ////dynamically load and add this .css file
- λ‘λ©μ μ΄λ―Έ ν΄λΉνμΌμ΄ λ‘λ©λμλμ§λ₯Ό 체ν¬νλ λ°©λ²
var filesadded="" //list of files already added
function checkloadjscssfile(filename, filetype){
if (filesadded.indexOf("["+filename+"]")==-1){
loadjscssfile(filename, filetype)
filesadded+="["+filename+"]" //List of files added in the form "[filename1],[filename2],etc"
}
else
alert("file already added!")
}
checkloadjscssfile("myscript.js", "js") //success
checkloadjscssfile("myscript.js", "js") //redundant file, so file not added
4. cssνμΌμ header/topμ μμΉν΄μΌνλ€.
λ¬Έμμ headerμ stylesheetsλ₯Ό μ΄λμν€κ² λλ©΄ νμ΄μ§μ λ‘λ©μ λμ± λΉ λ₯΄κ² ν μ μλ€.
μ΄ λ°©λ²μ νμ΄μ§μ λ λλ§μ ν¨μ¬ λΉ λ₯΄κ²ν΄μ€λ€. - yahoo(http://developer.yahoo.com/performance/rules.html#css_top)
headμ stylesheetsλ₯Ό μμΉμν΄μΌλ‘μ¨ λκ°μ§ λ¬Έμ λ₯Ό νΌν μ μλ€.
μ€νμΌμ΄ μ μ©λμ§ μμ λ΄μ©λ€μ΄ λΉ ν°μνμ΄μ§λ λ²μ©κ±°λ¦Όμ νΌν μ μλ€.
Steve Soudersμ¨κ° stylesheetsλ₯Ό μΉνμ΄μ§μ headerλΆλΆμ λ£μ§ μμμλμ λ¬Έμ μ μ
ν
μ€νΈν΄ λμλ€.(http://stevesouders.com/hpws/rule-css-top.php)
Before
<html>
<head>
<title>CSS</title>
<style>
body {
font-family:verdana;
margin:0;
padding:0;
}
h1 {
font-weight:700;
margin:5px 0;
}
......
......
......
</style>
</head>
</html>
After
<html>
<head>
<title>CSS</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
</html>
<html>
<head>
<title>CSS</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
</html>
5. @import λμ μ Linkλ₯Ό μ¬μ©ν΄λΌ
http://seye2.egloos.com/2319809 (μ΄κ³³μ μ°Έμ‘°νλ©΄ λλ€.)
6. CSSλ₯Ό μ§§κ² μ¨λΌ.
κ°μ μμ±λ€μ κ°μ΄ λ¬Άμ΄ κ·Έλ£Ήνν¨μΌλ‘μ¨ CSSλ₯Ό μ€μ΄κ³ μ΅μ ν μν€λλ° λμμ΄ λ κ²μ΄λ€.
μ¬λ¬μ€μ μμ±μ μ¬μ©νλ λμ μ νλμ λΌμΈμ μ¬μ©ν μ μλ€.
μλμ μμ λ₯Ό μ°Έμ‘°νλ©΄ λλ€.
CSS Shorthand
/* MARGIN */
h1 {margin:1em 0 2em 0.5em;}
h1 {margin-top:1em;
margin-right:0;
margin-bottom:2em;
margin-left:0.5em;
}
/* BORDER */
h1 {border:1px solid #000;}
h1 {border-width:1px;
border-style:solid;
border-color:#000;
}
/* BORDER WIDTH */
h1 {border-width:1px 2px 3px 4px;}
h1 {border-top-width:1px;
border-right-width:2px;
border-bottom-width:3px;
border-left-width:4px;
}
/* BACKGROUND */
div {background:#f00 url(background.gif) no-repeat fixed 0 0;}
div {background-color:#f00;
background-image:url(background.gif);
background-repeat:no-repeat;
background-attachment:fixed;
background-position:0 0;
}
/* FONT */
h1 {font:italic small-caps bold 1em/140% "Lucida Grande",sans-serif;}
h1 {font-style:italic;
font-variant:small-caps;
font-weight:bold;
font-size:1em;
line-height:140%;
font-family:"Lucida Grande",sans-serif;
}
/* LIST STYLE */
ul {list-style:square inside url(image.gif);}
ul {list-style-type:square;
list-style-position:inside;
list-style-image:url(image.gif);
}
/* OUTLINE */
h1 {outline:#f00 solid 2px;}
h1 {outline-color:#f00;
outline-style:solid;
outline-width:2px;
}
7. λΉμ·ν μ€νμΌμ κ·Έλ£Ήν
μ΄λ° μΌμ μ€λμκ°μ κ°λ°νμ μ½κ² λ°μλλ€. κ°μ μ€νμΌμ΄ μ‘΄μ¬νλ€λ κ²μ μμ΄λ²λ¦¬κ³
λ°λ³΅ν΄μ μ μΈνλ€. κ·Έλ£Ήν ν¨μΌλ‘μ¨ μ’λ μ½κ² λΆμν μ μκ³ , μ μ¬ν μ€νμΌμ
μ½κ² κ·Έλ£Ήν ν μ μλ€.
Before
h1 {padding:5px 0; font-family:verdana; font-weight:700;}
#box1 .heading {padding:5px 0; font-family:verdana; font-weight:700;}
#box2 .heading {padding:5px 0; font-family:verdana; font-weight:700;}
After
h1, #box1 .heading, #box2 .heading {padding:5px 0; font-family:verdana; font-weight:700;}
κ·Έλ¬λ λλΆλΆμ κ²½μ° CSS Stylesμ μλμ κ°μ΄ νλκ²μ΄ νμμ μ΄μ§λ μλ€.
Before
#nav a.home {padding:5px 0; font-family:verdana; font-weight:700; background:#fff url(home.gif) no-repeat 5px 5px}
#nav a.portfolio {padding:5px 0; font-family:verdana; font-weight:700; background:#fff url(portfolio.gif) no-repeat 5px 5px}
#nav a.contact {padding:5px 0; font-family:verdana; font-weight:700; background:#fff url(contact.gif) no-repeat 5px 5px}
#nav a.about {padding:5px 0; font-family:verdana; font-weight:700; background:#fff url(about.gif) no-repeat 5px 5px}
After
#nav a {padding:5px 0; font-family:verdana; font-weight:700; background:#fff no-repeat 5px 5px}
#nav a.home {background:url(home.gif)}
#nav a.portfolio {background:url(portfolio.gif)}
#nav a.contact {background:url(contact.gif)}
#nav a.about {background:url(about.gif)}
λ€μν μμ λ€μ 보μκ³ , μ΄κ²λ€μ CSSνμΌν¬κΈ°λ₯Ό μ€μ΄κ³ κ°λ
μ±μ λμ΄λλ° νλ₯ν λ°©λ²μ΄λ€.
8. μ€λ΄λ¦Όμ μ€μ΄μ
h2 {
font-family:verdana;
padding:0;
margin:5px 0;
color:#333;
text-decoration:underline;
}
/* you can do it like this */
h2 {font-family:verdana;padding:0;margin:5px 0;color:#333;text-decoration:underline;}
9. λ§μ§λ§ μΈλ―Έμ½λ‘ μ μμ μ.
h2 {font-family:verdana;color:#333;}
/* removed */
h2 {font-family:verdana;color:#333}
10. μ£Όμμ κ°λ¨νκ²
/************************************/
/* Content Page */
/************************************/
vs
/* content page */
11. μμ€μ μ κ°λ¨νκ²
μ 체 μ½λ 컬λ¬λ₯Ό μ¬μ©νλ λμ μ:
#FFFFFF, #113344, #AABBCC, #FF0000
μ€μ¬μ μ¬μ©ν μ μλ€.
#FFF, #134, #ABC, #F00
κ·Έλ¬λ μλμ κ°μ κ²½μ°λ λ°κΏ μ μλ€.:
#C4C4C4, #1A2B3C
12. pxμ μμ μ
h2 {padding:0px; margin:0px;}
/* removed */
h2 {padding:0; margin:0}
13. μ€μ¬μ(μ½μ΄λ±)μ μ¬μ©νμ
- μμμ μΈκΈνλ°λ‘ νμΌμ¬μ΄μ¦λ₯Ό μ€ μΌ μ μλ€.
14. λΆνμν ν΄λμ€μ¬μ©μ μ€μ΄μ.
- IE Conditional Comments λ΄μ link stylesheetsλ₯Ό μ§μνλ€.
- μΌλ°μ μΈ CSSν΅μ μ§μνλ€.(* html #fooλμ μ html #fooλ₯Ό μ¬μ©νλ€)
15. CSS Compression Toolsλ₯Ό μ¬μ©νλ€.
CSS Optimizer(http://www.cssoptimiser.com/)
Flumpcakes CSS Optimizer(http://flumpcakes.co.uk/css/optimiser/)
Clean CSS (http://flumpcakes.co.uk/css/optimiser/)
CSS Drive CSS Compressor(http://www.cssdrive.com/index.php/main/csscompressor/)
Online YUI Compressor(http://www.refresh-sf.com/yui/)
Style Neat(http://www.styleneat.com/)
μ°Έκ³ μ¬μ΄νΈ
- http://developer.yahoo.com/performance/rules.html
- http://www.sohtanaka.com/web-design/optimizing-css-tutorial/
- http://www.dailyblogtips.com/speed-up-your-site-optimize-your-css/
- http://www.pat-burt.com/web-development/10-tips-for-a-smaller-css-file
μλ¬Έ μ¬μ΄νΈ
- http://www.queness.com/post/588/15-ways-to-optimize-css-and-reduce-css-file-size
-http://seye2.egloos.com/2428232
'Before. 2021' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
ν μ€νΈ μ€λ°κΏ νκ·Έ (0) | 2012.12.21 |
---|---|
CSS3 box-Shadow (0) | 2012.12.13 |
textarea ν¬κΈ°μ‘°μ λ§κΈ° (0) | 2012.11.27 |
input νκ·Έ disabled & readonly μμ± (0) | 2012.11.26 |
μΉ μ κ·Όμ± μ§νλ³ μ λ¬Έκ°μ¬μ¬ νκ° κΈ°μ€ (0) | 2012.11.09 |