We are all familiar with the common interface development process which is:
* first, preparing an interface layout by a designer;
* then, making an HTML/CSS dummy;
* next, adding some JavaScript tricks with a help of JavaScript ninja;
* and, finally, having a server guy operating on templates and doing all the integration stuff.
Even while sometimes all these things are done by the same person, these are different roles and different project stages, and you switch from stage to stage to complete the development cycle.
When looking for performance gains, people often try to achieve that by changing the way the process is managed.
This presentation is about is a completely different approach which changes development from within. The goal is to convert a flat process with distinct stages into a continuous, uninterrupted development flow.
You can achieve this by decomposing a web interface into independent pieces (the so-called blocks), once and for all, and use them to build interfaces the same way bricks are used to build a house.
Thus, each of these interface components can be developed separately, which allows maintenance, refactoring and redesign to happen simultaneously on different interface parts, whenever necessary. You are not tied to a specific stage of project development anymore.
To make this happen, there are several principles you can follow:
1. Special project file structure, where files are stored the way the whole project can be built from components;
2. CSS guidelines that allow an interface piece to fit anywhere on any page without affecting other pieces;
3. In JavaScript, your functionality can be described in a highly semantic way usually unavailable with any other common approach.
All this magic is called BEM, which stands for Block, Element, and Modifier.
With my presentation, this technology will be revealed in greater detail, and magic explained bit by bit.
4. Search
Images Video Realty Social
Blogs Apps Jobs
Maps Mail Marketplace etc.
4
5. Next 30 minutes
• Usual development cycle
• Main problems it brings
• BEM solutions to the problems
• New development workflow
• Recently happened in BEM world
5
8. Usual development cycle and problems
• decomposition – every time
• every change starts from zero
• cannot reuse your own work
8
9.
10. BEM is a world on its own
• methodology of modularity
• file structure recommendations
• reusable libraries
• helpful tools & optimizers
• template engine
10
23. Independent CSS blocks
• a block has its name
Not id but classname selectors
• no tag selectors
• avoid cascade
23
24. Cascade: a way to express dependency
CSS
.header a {
text-decoration: none;
}
.main .photo { div.big_form .photo {
width: 150px; width: 250px;
height: 150px; height: 250px;
} }
.sidebar li {
list-style: none; .big_form .photo {
display: inline-block; width: 500px !important;
padding: 0 0.5em; }
}
24
25. Improving rendering performance
« The style system matches rules by starting with the key
selector, then moving to the left (looking for any
ancestors in the rule’s selector).
David Hyatt, MDN
mzl.la/UuwZql
25
26. Who uses the method
• Yandex
bit.ly/bem-riga-2012
• GitHub
bit.ly/github-css
• Harry Roberts
inuitcss.com
• OOCSS, SMACSS, etc.
26
62. What to do with BEM?
• follow recommendations
– modular everything (CSS, JS, etc.)
– file structure
– building projects
• participate
• write your own libraries
62