SlideShare une entreprise Scribd logo
1  sur  42
Site Optimization

 Dimitar Belchugov
    @belchugov
does performance really matter?
Of course it matters and you know it. So why do
we keep making slow sites that lead to a bad
user experience?

Let's not waste time showing millionaires
performance cases, let's get straight to the
point!
HTML
avoid inline/embedded code
1) Inline: the CSS is defined inside a style attribute and
   the JavaScript inside an onclick attribute for
   example, in any HTML tag;

2) Embedded: the CSS is defined inside a <style> tag and
the JavaScript inside a <script> tag;

3) External: the CSS is loaded from a <link> and the
JavaScript from the src attribute of the <script> tag.

> Useful tools / References
styles up top, scripts down bottom
<head>
<meta charset="UTF-8">
<title>Browser Diet</title>

<!-- CSS -->
<link rel="stylesheet" href="style.css" media="all">
</head>

<body>
<p>Lorem ipsum dolor sit amet.</p>

<!-- JS --> <script src="script.js"></script>
</body>
> References
minify your html
<p>Lorem ipsum dolor sit amet.</p>

<!-- My List -->
<ul>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
<li><a href="#"></a></li>
</ul>
minify your html
<p>Lorem ipsum dolor sit amet.</p> <!-- My List
--> <ul> <li><a href="#"></a></li> <li><a
href="#"></a></li> <li><a href="#"></a></li>
</ul>


On the right side you see a few samples of HTML
Compressor results with default settings.
> Useful tools / References
try out async
<script src="example.js"></script>

<script async src="example.js"></script>




> References
CSS
minify your stylesheets
.center {
 width: 960px;
 margin: 0 auto;
}

/* --- Structure --- */
.intro {
 margin: 100px;
 position: relative;
}

.center{width:960px;margin:0
auto}.intro{margin:100px;position:relative}
minify your stylesheets
For those that use pre-processors
like Sass, Less, and Stylus, it's possible to
configure your compiled CSS output to be
minified.




> Useful tools / References
combining multiple css files
<link rel="stylesheet" href="structure.css" media="all">
<link rel="stylesheet" href="banner.css" media="all">
<link rel="stylesheet" href="layout.css" media="all">
<link rel="stylesheet" href="component.css" media="all">
<link rel="stylesheet" href="plugin.css" media="all">


<link rel="stylesheet" href="main.css" media="all">


> Useful tools / References
prefer <link> over @import
There's two ways to include an external stylesheet in your page: either
via the <link> tag:
<link rel="stylesheet" href="style.css">

Or through the @import directive (inside an external stylesheet
or in an inline <style> tag):
@import url('style.css');


When you use the second option through an external stylesheet, the
browser is incapable of downloading the asset in parallel, which can
block the download of other assets.

> References
JAVASCRIPT
load 3rd party content asynchronously
var script = document.createElement('script'),
     scripts = document.getElementsByTagName('script')[0];
script.async = true;
script.src = url;
scripts.parentNode.insertBefore(script, scripts);




Alternatively, if you want to load multiple 3rd party
widgets, you can asynchronously load them with usingthis
script.
> Video / References
cache array lengths
var arr = new Array(1000), len, i;

for (i = 0; i < arr.length; i++) {
         // Bad - size needs to be recalculated 1000 times
}
for (i = 0, len = arr.length; i < len; i++) {
        // Good - size is calculated only 1 time and then
stored
}

> Results on JSPerf
cache array lengths
var links = document.getElementsByTagName('a'), len, i;
for (i = 0; i < links.length; i++) {
// Bad - each iteration the list of links will be recalculated to see if there was a change
}
for (i = 0, len = links.length; i < len; i++) {
  // Good - the list size is first obtained and stored, then compared each iteration
}
// Terrible: infinite loop example
for (i = 0; i < links.length; i++) {
document.body.appendChild(document.createElement('a'));
  // each iteration the list of links increases, never satisfying the termination condition
of the loop
  // this would not happen if the size of the list was stored and used as a condition
}
> References
avoid document.write
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js">
</script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"></script>')</script>

Attention: document.write performed during or after window.onload event replaces the entire content of the
current page.

<span>foo</span>
 <script>
 window.onload = function() {
 document.write('<span>bar</span>')
; };
 </script>

<span>foo</span>
<script> setTimeout(function() {
document.write('<span>bar</span>');
}, 1000);
window.onload = function() {
// ...
};
</script>

> References
minimize repaints and reflows
There is no doubt that excessive reflows and
repaints should be avoided, so instead of doing this:

var div = document.getElementById("to-measure"),
 lis = document.getElementsByTagName('li'), i, len;
 for (i = 0, len = lis.length; i < len; i++) {
 lis[i].style.width = div.offsetWidth + 'px';
}
minimize repaints and reflows
Do this:
var div = document.getElementById("to-measure"),
 lis = document.getElementsByTagName('li'),
widthToSet = div.offsetWidth,
 i, len;
for (i = 0, len = lis.length; i < len; i++) {
 lis[i].style.width = widthToSet + 'px';
}

> Demo / References
avoid unnecessary dom manipulations
// really bad!
for (var i = 0; i < 100; i++) {
document.getElementById("myList").innerHTML += "<span>" + i + "</span>";
}

// much better :)
var myList = "";

for (var i = 0; i < 100; i++) {
 myList += "<span>" + i + "</span>";
}

document.getElementById("myList").innerHTML = myList;


> Results on JSPerf
minify your script
BrowserDiet.app = function() {

var foo = true;

return {
bar: function() {
// do something
  }
};

};


BrowserDiet.app=function(){var a=!0;return{bar:function(){}}}

> Useful tools / References
combine multiple js files into one
Before                                 After
<script src="navbar.js"></script>      <script src="main.js"></script>
<script src="component.js"></script>
<script src="page.js"></script>
<script src="framework.js"></script>
<script src="plugin.js"></script>




                                       > Useful tools / References
JQUERY
always use the latest version of jquery
http://code.jquery.com/jquery-latest.js

<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.
min.js"></script>


Just like the wise Barney Stinson says, "New is
always better" :P


> References
use for instead of each
The use of native JavaScript functions nearly always
results in faster execution than the ones in jQuery.
For this reason, instead of using
the jQuery.each method, use JavaScript's
own for loop.

for ( var i = 0, len = a.length; i < len; i++ ) { e = a[i]; }



> Results on JSPerf / References
don't use jquery...
...unless it's absolutely necessary. :)

Why use the attr() method to search for an ID?

$('a').on('click', function() {
console.log( $(this).attr('id') );
});

If you can can get this attribute natively through this:

$('a').on('click', function() {
 console.log( this.id );
});

And it's faster.
> Results on JSPerf / References
IMAGES
use css sprites
This technique is all about grouping various images into a
single file.

.icon-foo {
  background-image: url('mySprite.png');
  background-position: -10px -10px; }
.icon-bar {
  background-image: url('mySprite.png');
  background-position: -5px -5px;
}

> Useful tools / References
data uri
Before:
.icon-foo {
 background-image: url('foo.png');
}

After:

.icon-foo {
 background-image:
url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQM
AAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUC
NdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII%3D');
}

> Useful tools / References
don't rescale images in markup
<img width="100" height="100" src="logo.jpg"
alt="Logo">




> References
optimize your images




> Useful tools / References
SERVER
enable smart caching
ExpiresActive On
ExpiresByType image/gif "access plus 6 months"
ExpiresByType image/jpeg "access plus 6 months"
ExpiresByType image/png "access plus 6 months"
ExpiresByType text/css "access plus 6 months"
ExpiresByType text/javascript "access plus 6 months"
ExpiresByType application/javascript "access plus 6
months“


> References
gzip
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE
application/javascript




> References
BONUS
diagnosis tools: your best friend
If you'd like to venture into this world of web
performance, it's crucial to install
the YSlowand PageSpeed extensions in your browser—
they'll be your best friends from now on.

Or, if you prefer online tools, visit the WebPageTest, HTTP
Archive, or PageSpeed sites.

In general each will analyse your site's performance and
create a report that gives your site a grade coupled with
invaluable advice to help you resolve the potential
problems.
that's it for today!
And remember, like all things in life, there's no
such thing as a silver bullet.
Questions
Thank you!

Contenu connexe

Tendances

Plone Interactivity
Plone InteractivityPlone Interactivity
Plone InteractivityEric Steele
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex DevsAaronius
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - GoodiesJerry Emmanuel
 
An in-depth look at jQuery UI
An in-depth look at jQuery UIAn in-depth look at jQuery UI
An in-depth look at jQuery UIPaul Bakaus
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web ComponentsColdFusionConference
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?Remy Sharp
 
Banners
BannersBanners
Bannersamogom
 
Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Aaron Gustafson
 
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...Shift Conference
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsReturn on Intelligence
 
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone developmentiPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone developmentEstelle Weyl
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWalter Ebert
 
Bilder einbinden ist kein Thema, oder?
Bilder einbinden ist kein Thema, oder?Bilder einbinden ist kein Thema, oder?
Bilder einbinden ist kein Thema, oder?Walter Ebert
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to JqueryAmzad Hossain
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1James Pearce
 
Angular Tutorial Freshers and Experienced
Angular Tutorial Freshers and ExperiencedAngular Tutorial Freshers and Experienced
Angular Tutorial Freshers and Experiencedrajkamaltibacademy
 

Tendances (20)

Jquery tutorial
Jquery tutorialJquery tutorial
Jquery tutorial
 
Plone Interactivity
Plone InteractivityPlone Interactivity
Plone Interactivity
 
JavaScript for Flex Devs
JavaScript for Flex DevsJavaScript for Flex Devs
JavaScript for Flex Devs
 
Web performance essentials - Goodies
Web performance essentials - GoodiesWeb performance essentials - Goodies
Web performance essentials - Goodies
 
An in-depth look at jQuery UI
An in-depth look at jQuery UIAn in-depth look at jQuery UI
An in-depth look at jQuery UI
 
The Future of CSS with Web Components
The Future of CSS with Web ComponentsThe Future of CSS with Web Components
The Future of CSS with Web Components
 
HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?HTML5: friend or foe (to Flash)?
HTML5: friend or foe (to Flash)?
 
Banners
BannersBanners
Banners
 
Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]Performance as User Experience [An Event Apart Denver 2017]
Performance as User Experience [An Event Apart Denver 2017]
 
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
More Than You Ever Wanted to Know About Resource Hints - Harry Roberts (CSS W...
 
Introduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.jsIntroduction to Backbone.js & Marionette.js
Introduction to Backbone.js & Marionette.js
 
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone developmentiPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
iPhone Web Applications: HTML5, CSS3 & dev tips for iPhone development
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
WordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFMWordPress-Templates mit Twig erstellen - PHPUGFFM
WordPress-Templates mit Twig erstellen - PHPUGFFM
 
Bilder einbinden ist kein Thema, oder?
Bilder einbinden ist kein Thema, oder?Bilder einbinden ist kein Thema, oder?
Bilder einbinden ist kein Thema, oder?
 
Bilder usw...
Bilder usw...Bilder usw...
Bilder usw...
 
1cst
1cst1cst
1cst
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
 
Angular Tutorial Freshers and Experienced
Angular Tutorial Freshers and ExperiencedAngular Tutorial Freshers and Experienced
Angular Tutorial Freshers and Experienced
 

En vedette

Cic standard presentation
Cic standard presentationCic standard presentation
Cic standard presentationindustrialimmex
 
Happy birthday deepika ma'am
Happy birthday deepika ma'amHappy birthday deepika ma'am
Happy birthday deepika ma'amgarimagd
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...Yury Leonychev
 
Sonia mam ppt
Sonia mam pptSonia mam ppt
Sonia mam pptgarimagd
 
Mothers day @ gd goenka lapetite(pitampura)
Mothers day @ gd goenka lapetite(pitampura)Mothers day @ gd goenka lapetite(pitampura)
Mothers day @ gd goenka lapetite(pitampura)garimagd
 
Fast detection of Android malware: machine learning approach
Fast detection of Android malware: machine learning approachFast detection of Android malware: machine learning approach
Fast detection of Android malware: machine learning approachYury Leonychev
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Yury Leonychev
 
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...Elettra Rossellini
 
Яндекс.АккаунтМенеджер - Mobius 2015
Яндекс.АккаунтМенеджер - Mobius 2015Яндекс.АккаунтМенеджер - Mobius 2015
Яндекс.АккаунтМенеджер - Mobius 2015Yury Leonychev
 
Cast iron presentation
Cast iron presentationCast iron presentation
Cast iron presentationSura Gonzalez
 

En vedette (13)

Red
RedRed
Red
 
Cic standard presentation
Cic standard presentationCic standard presentation
Cic standard presentation
 
Happy birthday deepika ma'am
Happy birthday deepika ma'amHappy birthday deepika ma'am
Happy birthday deepika ma'am
 
Css frameworks
Css frameworksCss frameworks
Css frameworks
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, Japan...
 
Sonia mam ppt
Sonia mam pptSonia mam ppt
Sonia mam ppt
 
Mothers day @ gd goenka lapetite(pitampura)
Mothers day @ gd goenka lapetite(pitampura)Mothers day @ gd goenka lapetite(pitampura)
Mothers day @ gd goenka lapetite(pitampura)
 
Mobile enterprise
Mobile enterpriseMobile enterprise
Mobile enterprise
 
Fast detection of Android malware: machine learning approach
Fast detection of Android malware: machine learning approachFast detection of Android malware: machine learning approach
Fast detection of Android malware: machine learning approach
 
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
Ml based detection of users anomaly activities (20th OWASP Night Tokyo, English)
 
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...
Patricia van voorhis,_michael_c._braswell,_david Correctional Counseling and ...
 
Яндекс.АккаунтМенеджер - Mobius 2015
Яндекс.АккаунтМенеджер - Mobius 2015Яндекс.АккаунтМенеджер - Mobius 2015
Яндекс.АккаунтМенеджер - Mobius 2015
 
Cast iron presentation
Cast iron presentationCast iron presentation
Cast iron presentation
 

Similaire à Site optimization

Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web PerformanceAdam Lu
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesDoris Chen
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Ted Kulp
 
Being a tweaker modern web performance techniques
Being a tweaker   modern web performance techniquesBeing a tweaker   modern web performance techniques
Being a tweaker modern web performance techniquesChris Love
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...tdc-globalcode
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup PerformanceJustin Cataldo
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucksTim Wright
 
HTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleHTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleChris Mills
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJSZhang Xiaoxue
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web developmentAlberto Apellidos
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsAlessandro Molina
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Phil Leggetter
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1Heather Rock
 

Similaire à Site optimization (20)

Enhance Web Performance
Enhance Web PerformanceEnhance Web Performance
Enhance Web Performance
 
Ajax Performance Tuning and Best Practices
Ajax Performance Tuning and Best PracticesAjax Performance Tuning and Best Practices
Ajax Performance Tuning and Best Practices
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Being a tweaker modern web performance techniques
Being a tweaker   modern web performance techniquesBeing a tweaker   modern web performance techniques
Being a tweaker modern web performance techniques
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
HTML5
HTML5HTML5
HTML5
 
Slow kinda sucks
Slow kinda sucksSlow kinda sucks
Slow kinda sucks
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 
HTML5 and CSS3 Shizzle
HTML5 and CSS3 ShizzleHTML5 and CSS3 Shizzle
HTML5 and CSS3 Shizzle
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
前端MVC之BackboneJS
前端MVC之BackboneJS前端MVC之BackboneJS
前端MVC之BackboneJS
 
Webpack
Webpack Webpack
Webpack
 
Introduction to web development
Introduction to web developmentIntroduction to web development
Introduction to web development
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
Why You Should be Using Web Components Right Now. And How. ForwardJS July 2015
 
GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1GDI Seattle Intermediate HTML and CSS Class 1
GDI Seattle Intermediate HTML and CSS Class 1
 

Dernier

Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxRosabel UA
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 

Dernier (20)

Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Presentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptxPresentation Activity 2. Unit 3 transv.pptx
Presentation Activity 2. Unit 3 transv.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 

Site optimization

  • 1. Site Optimization Dimitar Belchugov @belchugov
  • 2. does performance really matter? Of course it matters and you know it. So why do we keep making slow sites that lead to a bad user experience? Let's not waste time showing millionaires performance cases, let's get straight to the point!
  • 4. avoid inline/embedded code 1) Inline: the CSS is defined inside a style attribute and the JavaScript inside an onclick attribute for example, in any HTML tag; 2) Embedded: the CSS is defined inside a <style> tag and the JavaScript inside a <script> tag; 3) External: the CSS is loaded from a <link> and the JavaScript from the src attribute of the <script> tag. > Useful tools / References
  • 5. styles up top, scripts down bottom <head> <meta charset="UTF-8"> <title>Browser Diet</title> <!-- CSS --> <link rel="stylesheet" href="style.css" media="all"> </head> <body> <p>Lorem ipsum dolor sit amet.</p> <!-- JS --> <script src="script.js"></script> </body> > References
  • 6. minify your html <p>Lorem ipsum dolor sit amet.</p> <!-- My List --> <ul> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> </ul>
  • 7. minify your html <p>Lorem ipsum dolor sit amet.</p> <!-- My List --> <ul> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> </ul> On the right side you see a few samples of HTML Compressor results with default settings. > Useful tools / References
  • 8. try out async <script src="example.js"></script> <script async src="example.js"></script> > References
  • 9. CSS
  • 10. minify your stylesheets .center { width: 960px; margin: 0 auto; } /* --- Structure --- */ .intro { margin: 100px; position: relative; } .center{width:960px;margin:0 auto}.intro{margin:100px;position:relative}
  • 11. minify your stylesheets For those that use pre-processors like Sass, Less, and Stylus, it's possible to configure your compiled CSS output to be minified. > Useful tools / References
  • 12. combining multiple css files <link rel="stylesheet" href="structure.css" media="all"> <link rel="stylesheet" href="banner.css" media="all"> <link rel="stylesheet" href="layout.css" media="all"> <link rel="stylesheet" href="component.css" media="all"> <link rel="stylesheet" href="plugin.css" media="all"> <link rel="stylesheet" href="main.css" media="all"> > Useful tools / References
  • 13. prefer <link> over @import There's two ways to include an external stylesheet in your page: either via the <link> tag: <link rel="stylesheet" href="style.css"> Or through the @import directive (inside an external stylesheet or in an inline <style> tag): @import url('style.css'); When you use the second option through an external stylesheet, the browser is incapable of downloading the asset in parallel, which can block the download of other assets. > References
  • 15. load 3rd party content asynchronously var script = document.createElement('script'), scripts = document.getElementsByTagName('script')[0]; script.async = true; script.src = url; scripts.parentNode.insertBefore(script, scripts); Alternatively, if you want to load multiple 3rd party widgets, you can asynchronously load them with usingthis script. > Video / References
  • 16. cache array lengths var arr = new Array(1000), len, i; for (i = 0; i < arr.length; i++) { // Bad - size needs to be recalculated 1000 times } for (i = 0, len = arr.length; i < len; i++) { // Good - size is calculated only 1 time and then stored } > Results on JSPerf
  • 17. cache array lengths var links = document.getElementsByTagName('a'), len, i; for (i = 0; i < links.length; i++) { // Bad - each iteration the list of links will be recalculated to see if there was a change } for (i = 0, len = links.length; i < len; i++) { // Good - the list size is first obtained and stored, then compared each iteration } // Terrible: infinite loop example for (i = 0; i < links.length; i++) { document.body.appendChild(document.createElement('a')); // each iteration the list of links increases, never satisfying the termination condition of the loop // this would not happen if the size of the list was stored and used as a condition } > References
  • 18. avoid document.write <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"> </script> <script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.0.min.js"></script>')</script> Attention: document.write performed during or after window.onload event replaces the entire content of the current page. <span>foo</span> <script> window.onload = function() { document.write('<span>bar</span>') ; }; </script> <span>foo</span> <script> setTimeout(function() { document.write('<span>bar</span>'); }, 1000); window.onload = function() { // ... }; </script> > References
  • 19. minimize repaints and reflows There is no doubt that excessive reflows and repaints should be avoided, so instead of doing this: var div = document.getElementById("to-measure"), lis = document.getElementsByTagName('li'), i, len; for (i = 0, len = lis.length; i < len; i++) { lis[i].style.width = div.offsetWidth + 'px'; }
  • 20. minimize repaints and reflows Do this: var div = document.getElementById("to-measure"), lis = document.getElementsByTagName('li'), widthToSet = div.offsetWidth, i, len; for (i = 0, len = lis.length; i < len; i++) { lis[i].style.width = widthToSet + 'px'; } > Demo / References
  • 21. avoid unnecessary dom manipulations // really bad! for (var i = 0; i < 100; i++) { document.getElementById("myList").innerHTML += "<span>" + i + "</span>"; } // much better :) var myList = ""; for (var i = 0; i < 100; i++) { myList += "<span>" + i + "</span>"; } document.getElementById("myList").innerHTML = myList; > Results on JSPerf
  • 22. minify your script BrowserDiet.app = function() { var foo = true; return { bar: function() { // do something } }; }; BrowserDiet.app=function(){var a=!0;return{bar:function(){}}} > Useful tools / References
  • 23. combine multiple js files into one
  • 24. Before After <script src="navbar.js"></script> <script src="main.js"></script> <script src="component.js"></script> <script src="page.js"></script> <script src="framework.js"></script> <script src="plugin.js"></script> > Useful tools / References
  • 26. always use the latest version of jquery http://code.jquery.com/jquery-latest.js <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery. min.js"></script> Just like the wise Barney Stinson says, "New is always better" :P > References
  • 27.
  • 28. use for instead of each The use of native JavaScript functions nearly always results in faster execution than the ones in jQuery. For this reason, instead of using the jQuery.each method, use JavaScript's own for loop. for ( var i = 0, len = a.length; i < len; i++ ) { e = a[i]; } > Results on JSPerf / References
  • 29. don't use jquery... ...unless it's absolutely necessary. :) Why use the attr() method to search for an ID? $('a').on('click', function() { console.log( $(this).attr('id') ); }); If you can can get this attribute natively through this: $('a').on('click', function() { console.log( this.id ); }); And it's faster. > Results on JSPerf / References
  • 31. use css sprites This technique is all about grouping various images into a single file. .icon-foo { background-image: url('mySprite.png'); background-position: -10px -10px; } .icon-bar { background-image: url('mySprite.png'); background-position: -5px -5px; } > Useful tools / References
  • 32. data uri Before: .icon-foo { background-image: url('foo.png'); } After: .icon-foo { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQM AAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUC NdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII%3D'); } > Useful tools / References
  • 33. don't rescale images in markup <img width="100" height="100" src="logo.jpg" alt="Logo"> > References
  • 34. optimize your images > Useful tools / References
  • 36. enable smart caching ExpiresActive On ExpiresByType image/gif "access plus 6 months" ExpiresByType image/jpeg "access plus 6 months" ExpiresByType image/png "access plus 6 months" ExpiresByType text/css "access plus 6 months" ExpiresByType text/javascript "access plus 6 months" ExpiresByType application/javascript "access plus 6 months“ > References
  • 37. gzip AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/javascript > References
  • 38. BONUS
  • 39. diagnosis tools: your best friend If you'd like to venture into this world of web performance, it's crucial to install the YSlowand PageSpeed extensions in your browser— they'll be your best friends from now on. Or, if you prefer online tools, visit the WebPageTest, HTTP Archive, or PageSpeed sites. In general each will analyse your site's performance and create a report that gives your site a grade coupled with invaluable advice to help you resolve the potential problems.
  • 40. that's it for today! And remember, like all things in life, there's no such thing as a silver bullet.