Fast         Fast    ER   Fast    EST




a little journey into Website Optimization
@stelian
web designer @digiti
believes in optimization
“People don’t like
    to wait”


             - Captain Obvious
40% of people abandon a
   website that takes
more than 3 seconds
        to load.


                   - Forrester Research
online shoppers expect
      pages to load in
    2 seconds


              - Forrester Research
on the web   250ms might
    win you the race


             - Google & Microsoft studies
Page load times affect
  online businesses
+500ms
                               -3%



                     Traffic
         Page load
           time
+500ms

                               -1.2%


                     Revenue
         Page load
           time
+100ms
                             -1%


         Page load


                     Sales
           time
“80-90% of the end-user
response time is spent on the
     front-end”


              - Steve Saunders, Google
Objectives
 Low number of files
 Small file size
 Fast rendering
Low number of files
"Every HTTP request is
 a gamble. A chance to
        fail."

                  - Scott Jehl
6
Connections per Hostname
Use CSS Sprites
1 CSS file
1 CSS file, ideally
29
Use @media print
  instead of print.css
1 JS file per hostname
40+
Small file size
Write
 semantic HTML
avoiding unnecessary elements
Minify the
javascript
Smaller CSS
use a reset.css file to avoid repetition
use shorthand properties
*design with consistency
remove unused styling



                        * for the designers
Normal
body{
    font-family: "Lucida Grande", Lucida, Verdana, sans-serif;
    font-size: 1em;
    line-height: 1.5em;
    font-style: italic;
    font-weight: bold;
}




                     Shorthand
body{
    font: italic bold 1em/1.5em "Lucida Grande", Lucida, Verdana, sans-serif;
}
Consistency: font-size

                                 23%
10+                                    100+
      78%


       The number of font-size
            declarations




                   Alexa top 1000 websites
Consistency: patterns




           source: stubbornella.org
Minify the
  CSS
Use font subsets
     if possible
Choose the
right image format

               binary files (images,
                    PDFs, ...)
        84%




         Alexa top 1000 websites
GIF
Only for animations
PNG-8
for small dimensions and no need for
          true color support;
    recommended for illustrations
PNG-8 Alpha Transparency
         Fireworks
PNG-8 Alpha Transparency
       ImageAlpha (Free)
PNG-24
  when in need for high quality
graphics, although it tends to get
           bigger in size
Use posterization to
 reduce the number of
colors in a PNG-24 file
JPEG
great for large images that contain
         photographic data
JPEG tips
80% quality is usually good enough
try to align edges to an 8x8 pixel grid
use JPEG selective quality in FW
JPEG
Left square aligned to the 8x8 grid,
          right one not
JPEG Selective Quality
    in Fireworks
Use ImageOptim
  to compress images further
Alternatives: smush.it, punypng,
            jpegmini
Original   PNG-8 + Alpha Transparency

1068 KB               263 KB
Original   PNG-8 + Alpha +ImageOptim

1068 KB               228 KB
Fast rendering
Cache static files
Cache static files
    forever
“e fastest HTTP
request is the one not
       made”
Using .htaccess
Header unset Pragma
FileETag None
Header unset ETag
 
# cache images for 10 years
<FilesMatch ".(ico|pdf|jpg|jpeg|png|gif)$">
  Header set Cache-Control "max-age=315360000, public, must-revalidate"
  Header unset Last-Modified
</FilesMatch>
 
# cache html/htm/xml/txt files for 2 hours
<FilesMatch ".(html|htm|xml|txt|xsl)$">
  Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>




             this is just an example;
     for best results, use HTML5 Boilerplate
Cache AJAX requests
Faster CSS
                    Don't use @import
                    Stay away from *
                    Avoid using a tag as a key


body * {...}
body > * {...}
ul.active li a {...}
ul.active > li > a {...}
Use CSS3 responsibly
don’t overuse border-radius, box-shadow,
                gradients




                         http://perfectionkills.com
Use domain sharding
  to increase the number of
   concurrent connections
Use a CDN
Content Delivery Network
Use CDN hosted
  JS libraries
Specify the jQuery version
                     for better caching



http://code.jquery.com/jquery-latest.min.js                       no cache
http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js     1 hour
http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js   1 year
Always load scripts
asyncroniusly and put
them at the bottom of
      the page
Compress only
compressible resources
 HTML, CSS, JS, XML, SVG, ICO
 use GZIP instead of Deflate
 use lowercase for better compression
 HTML5 Boilerplate .htaccess recommened
e favicon
have one to avoid a 404
load it from a subdomain
compress it
cache it forever
Avoid mixed content
            warnings

http://code.jquery.com/jquery-latest.min.js

//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
Minimize reflows
Watch out for 404
   favicon
   apple touch icons
   apple-touch-icon-ZxZ-precomposed (android)

   crossdomain.xml
Trigger hardware
accelerated CSS in iOS
Test
PageSpeed, Yslow
Measure
      Google Analytics Site
             Speed
//default sample rate is 1%
_gaq.push(['_setSiteSpeedSampleRate', 5]);
So, what now?
Cheat
  Lie
Deceive
Performance
 Perception
Apple
 The iPhone saves a screenshot of every app
when it closes. So when you relaunch the app
        it loads that screenshot first.
Instagram
Instagram
Instagram
Amazon




         Priority Loading
Tools & Resources(1 of 2)
Tools
๏ ImageOptim
๏ ImageAlpha
๏ HTML5 Boilerplate
๏ Smush.it - PunyPNG - JPEGmini - PNGGauntlet (Win)
๏ Online YUI Compressor
๏ CSS Sprite Generator - CSSsprite Photoshop script
๏ Page Speed - YSlow

Resources
๏ Akamai Reveals 2 Seconds as the New Threshold of Acceptability for eCommerce Web Page Response Times
๏ How Loading Time Affects Your Bottom Line (Infographic)
๏ For Impatient Web Users, an Eye Blink Is Just Too Long to Wait
๏ Facebook pages that are 500ms slower result in a 3% drop-off in traffic (PDF)
๏ If Google increased page load by 500ms it would cost them 1.2% of their revenue (Video)
๏ Every 100ms of latency costs Amazon 1% of profit
๏ The Performance Golden Rule
Tools & Resources(2 of 2)
๏ Most Browsers Allow 6 Concurrent Connections per Hostname
๏ Top 5 Mistakes of Massive CSS (Video + Graphs)
๏ How to create CSS objects? Get the granularity right!
๏ HTTP Compression use by Alexa Top 1000
๏ Profiling CSS for fun and profit. Optimization notes. (CSS3 Performance)
๏ Maximize Your Chances of Caching Your jQuery
๏ Lose the Wait: HTTP Compression
๏ Instagram and Optimizing Favicons
๏ Use Lowercase Markup For Better Compression
๏ Small site? Raise your page load time calculation sample to 100%
๏ The iPhone’s Perceived Performance
๏ The 3 White Lies Behind Instagram’s Lightning Speed
๏ Making a Slow Site Appear Fast

A little journey into website optimization