Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Web Performance Optimization

Web Performance Optimization

Un sito web più veloce influisce positivamente sull'esperienza
dell'utente e sulle performance sui motori di ricerca. In questa
sessione vedremo come analizzare e migliorare i tempi di caricamento
delle pagine facendo riferimento a strumenti specializzati e best
practice per ottenere subito i migliori risultati con uno sforzo
contenuto.

Alessandro Martin

December 05, 2009
Tweet

More Decks by Alessandro Martin

Other Decks in Technology

Transcript

  1. 2 Agenda  La velocità è importante?  Da cosa

    dipende?  Best practice  Analisi dal vivo  Conclusioni  → Novità
  2. 11 Ha il maggiore impatto:  Velocità del server? 

    Velocità codice?  Velocità del database?
  3. 13 2 o 3 cose che sapete Browser Server GET

    /pippo.html GET /style.css GET /script.js GET /img.jpg pippo.html style.css script.js img.jpg
  4. 15 80% del tempo di caricamente percepito dall'utente è speso

    nel frontend è qui che dobbiamo lavorare..
  5. 16 Buone notizie  Ottimizzare il frontend è facile 

    Risultati certi  Molti tool  Best practice ben definite...
  6. 17

  7. 18 Riduci le Richieste HTTP Usa un Content Delivery Network

    Sfrutta Gzip Metti gli Script alla Fine Aggiungi un Expires Header Minimizza Javascript e CSS
  8. 19 Riduci le richieste HTTP  1 componente = 1

    richiesta HTTP  Ogni richiesta HTTP occupa tempo  Meno richieste → più velocità Browser Server
  9. 20 Riduci le richieste HTTP  JS e CSS combinati

     Image map  Immagini inline (data URI) <img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//U b//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hL njM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJ jPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7" width="16" height="14" alt="embedded folder icon"> <?php echo base64_encode(file_get_contents("../images/folder16.gif")) ?>
  10. 26 Content Delivery Network <script src="http://www.google.com/jsapi"></script> <script> // Load jQuery

    google.load("jquery", "1"); //do some stuff... </script>  Costoso (es. Akamai)  CDN dei poveri ;-)
  11. 27 Abilita Gzip Zip... Unzip... Browser Accept-econding:gzip 1 Server 2

    Browser Accept-econding:gzip 4 Server Content-econding:gzip 3
  12. 32 Expires headers ~80% delle pageview hanno una CACHE inizializzata

    Fonte: http://developer.yahoo.com/performance/rules.html#expires
  13. 36 Minimizzare JS e CSS (function(){ var // Will speed

    up references to window, and allows munging its name. window = this, // Will speed up references to undefined, and allows munging its name. undefined, // Map over jQuery in case of overwrite _jQuery = window.jQuery, (function(){var l=this,g,y=l.jQuery,p=l. $,o=l.jQuery=l.$=function(E,F){return new o.fn.init(E,F)},D=/^[^<]*(<(.|\s)+>) [^>]*$|^#([\w-]+)$/,f=/^.[^:#\ [\.,]*$/;o.fn=o.prototype={init:function(E, H){E=E||document;if(E.nodeType) {this[0]=E;this.length=1;this.context=E;ret urn this}if(typeof E==="string"){var G=D.exec(E);if(G&&(G[1]||!H)){if(G[1]) {E=o.clean([G[1]],H)}else{var I=document.getElementById(G[3]); 117KB 56KB
  14. 39 Strumenti  Hammer Head – tempi di caricamento 

    Yslow – analisi made in Yahoo!  PageSpeed – analisi made in Google  Spriteme – CSS sprites made easy  Smush – comprime le immagini  YUI Compressor – minifica JS e CSS  site-perf.com – analisi  Firebug – net panel
  15. 44  Una grande opportunità  Poco intrusiva  Più

    visite  Più conversioni  Meno risorse HW  Meno banda
  16. 48 Bonus: GA goes Async var _gaq = _gaq ||

    []; _gaq.push(['_setAccount', 'UA-XXXXX-X']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; ga.setAttribute('async', 'true'); document.documentElement.firstChild.appendChild(ga); })();