SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
PHPNW09



            Thomas Weinert
Optimizing Your Frontend Performance
About Me
●   Application Developer
    –   PHP
    –   XSLT/XPath
    –   (some) Javascript
●   papaya CMS
    –   PHP based Content Management System
    –   uses XSLT for Templates
How to scale you webpage?
●   Hardware
●   Backend
●   Frontend
Hardware
●   More hardware
●   Better hardware
●   Moores Law
    –   Transistors doubling every 18 months
    –   Transistors != Performance
●   Distributed systems are complex
●   Think about environment
Backend
●   External data sources are slow
    –   SQL
    –   Files
    –   Network
●   Locking is slower
●   Memory is faster
    –   but less secure
Mini/Micro Optimisations
●   Myths
    –   echo vs. print
    –   ' vs. "
●   Objects vs. functions vs. linear source
●   Template systems
Mini/Micro Optimisations




  DON'T DO IT
Yahoo!
●   Yahoo!'s Exceptional Performance team
    –   Yahoo!'s Exceptional Performance team
        evangelizes best practices for improving web
        performance. They conduct research, build tools,
        write articles and blogs, and speak at conferences.
        Their best practices center around the rules for high
        performance web sites.
    –   http://developer.yahoo.com/performance/
Results
●   80% of the end-user response time is spent on
    the front-end.
Firebug
●   Firefox extension
●   Analyze and manipulate
    –   requests, page structure, CSS
●   Javascript debugger
Firebug Requests
Firebug Request II
HTTPFox
●   Firefox Extension
●   Log of all HTTP requests
       –   Redirects
       –   Cached requests
YSlow
●   Why (is your web page) slow
●   Set of rules
●   Firebug extension
Yslow: Performance View
Yslow: Stats
Yslow: Components
Yslow: Tools
Google Page Speed
●   Firebug extension
●   CSS complexitiy
Google Page Speed Screenshot
Make Fewer HTTP Requests
●   Combined files
    –   CSS
    –   JavaScript
●   CSS sprites
Combined files
●   Release process
●   CSS
    –   Consider URLs
●   JavaScript
    –   Minify
    –   Obfuscate
CSS Sprites
●   Elements with fixed size
●   Background image
●   Disable repeat
●   Negative positions
CSS Icons
●   Raster of icons
●   No repeat
●   Fixed size
    <div> or <span>
CSS Backgrounds
●   Gradient
●   Repeat in one
    direction
Minify Javascript
●   Most JS libraries provide a minified version
●   YUI Compressor:
    http://developer.yahoo.com/yui/compressor/
    –   JS and CSS
●   Packer
    –   Webpage, .Net, Perl, PHP
    –   http://dean.edwards.name/packer/
#2 Use A CDN
●   Content Delivery Network
    –   Akamai Technologies
    –   Mirror Image Internet
    –   Limelight Networks
●   Bring the content to your users
    –   Geographic distance
    –   Physics is still here
●   Only for large sites
●   Dynamic content is complex
Headers
●   Expires
●   Cache-Control
    –   Session-Management
●   304 Not Modified
Expires
●   Apache mod_expire
●


●     <IfModule mod_expires.c>
●       ExpiresDefault "access plus 1 month"
●       ExpiresActive on
●     </IfModule>
Cache-Control
●   None
    –   no caching
    –   default for sessions
●   Private
    –   cacheable in browser cache
●   Public
    –   cacheable in browser cache and proxies
304 Not Modified
●   Send Etag and Modfication date
    –   Etag: "some hash"
    –   Last-Modified: Thu, 12 Sep 2008 11:00:00 GMT
●   Request headers
    –   If-Modified-Since: Tue, 12 Sep 2008 11:00:00 GMT
    –   If-None-Match: "some hash"
●   Response headers
    –   HTTP/1.1 304 Not Modified
Gzip Components
●   Gzip != Zip
    –   only compression
    –   no packaging
    –   tar.gz
●   Good browser support
    –   Accept-Encoding: gzip, deflate
    –   Content-Encoding: gzip
    –
Gzip in Apache
●   mod_gzip
●   mod_deflate
    –   filter chain, works on dynamic content, too
●


    –   http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
Gzip In PHP 5
<?php
 ob_start('ob_gzhandler');
 ...
Gzip In PHP 5
<?php
  if (function_exists('ob_gzhandler')) {
      ob_start('ob_gzhandler');
  }
  ...
Gzip Problems
●   Not supported:
       –   Transfer-Encoding: chunked
       –   HTTP 1.0 client (old Squids)
Configure ETags
●   Browser still asks webserver
●   Server specific
    –   CDN
    –   Load balancer with multiple servers
●   Apache
    –     FileETag none
●   IIS
    –   http://support.microsoft.com/?id=922733
Split requests across domains
●   HTTP 1.1 suggests 2 parallel requests per
    domain
●   Separate content by function
    –   www.domain.tld
    –   themes.domain.tld
    –   usercontent.domain.tld (security)
●   Optimisation tools change the option
●   Consider cookie domains
Reduce DNS Lookups
●   DNS maps host names to ips
●   Needs time
    –   20-120 milliseconds
●   Cached in browser
Avoid Redirects
●   Obviously addition requests
●   Only cached with explicit headers

●   http://www.domain.tld
    –   → http://www.domain.tld/
Put Stylesheets at the Top
●   Progressive display of the page
●   Page appears to load faster
●   W3C specifications
Put Scripts at the Bottom
●   Scripts block parallel downloads
    –   defer attribute in MSIE
●   onload() event
    –   used by most libraries


●   Problem: document.write()
    –   Counter
    –   Banners
Avoid CSS Expressions
●   MSIE from version 5
    –   cross browser experience
●   JavaScript inside CSS
●   Evaluated
    –   page render
    –   resize
    –   scrolling
    –   mouse movements (hover)
JavaScript And CSS Files
●   Do not embed JS/CSS in your pages
    –   No <script>...</script>
    –   No <style>...</style>
●   Seperate caching headers
●   Revision parameter (style.css?rev=1234)
    –   Get parameter
    –   Unique URL for browser
    –   Possibly in path/filename
Remove Duplicate Scripts
●   Team size
●   Standard scripts
    –   XMLRPC, JQuery, Prototype
●   Script module for your template system

●   $templatesystem->addScript('foo.js');
Make Ajax Cacheable
●   Often AJAX applications avoid caching
    –   http://some.domain.tld/ajax.file?t=randomvalue
●   A lot of requests
●   Use more static URLs
References
●   Slides: http://www.a-basketful-of-papayas.net/
●   Yahoo Performance Team
     –   http://developer.yahoo.com/performance/
●   Google Page Speed
     –   http://code.google.com/intl/en-UK/speed/page-speed/
●   Apache GZIP
     –   http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
●   No Etag in IIS
     –   http://support.microsoft.com/?id=922733

Más contenido relacionado

La actualidad más candente

캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라Park Chunduck
 
Web Optimization Level: Paranoid
Web Optimization Level: ParanoidWeb Optimization Level: Paranoid
Web Optimization Level: Paranoidrobin_sy
 
Website performance optimization QA
Website performance optimization QAWebsite performance optimization QA
Website performance optimization QADenis Dudaev
 
High-performance high-availability Plone
High-performance high-availability PloneHigh-performance high-availability Plone
High-performance high-availability PloneGuido Stevens
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and ScalingGerald Villorente
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPChau Thanh
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable CacheMobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable CacheBlaze Software Inc.
 
High Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlHigh Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlJoomla!Days Netherlands
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningTimothy Wood
 
Drupal 7 performance and optimization
Drupal 7 performance and optimizationDrupal 7 performance and optimization
Drupal 7 performance and optimizationShafqat Hussain
 
WordPress Hosting Best Practices - Do's and Don't s | WordPress Trivandrum
WordPress Hosting Best Practices - Do's and Don't s  | WordPress TrivandrumWordPress Hosting Best Practices - Do's and Don't s  | WordPress Trivandrum
WordPress Hosting Best Practices - Do's and Don't s | WordPress TrivandrumWordPress Trivandrum
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadMarius Adrian Popa
 

La actualidad más candente (18)

캐시 분산처리 인프라
캐시 분산처리 인프라캐시 분산처리 인프라
캐시 분산처리 인프라
 
Fluent 2012 v2
Fluent 2012   v2Fluent 2012   v2
Fluent 2012 v2
 
Web Optimization Level: Paranoid
Web Optimization Level: ParanoidWeb Optimization Level: Paranoid
Web Optimization Level: Paranoid
 
Website performance optimization QA
Website performance optimization QAWebsite performance optimization QA
Website performance optimization QA
 
High-performance high-availability Plone
High-performance high-availability PloneHigh-performance high-availability Plone
High-performance high-availability Plone
 
Drupal Performance and Scaling
Drupal Performance and ScalingDrupal Performance and Scaling
Drupal Performance and Scaling
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable CacheMobile & Desktop Cache 2.0: How To Create A Scriptable Cache
Mobile & Desktop Cache 2.0: How To Create A Scriptable Cache
 
High Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nlHigh Performance - Joomla!Days NL 2009 #jd09nl
High Performance - Joomla!Days NL 2009 #jd09nl
 
Scalability
ScalabilityScalability
Scalability
 
WordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & TuningWordCamp RVA 2011 - Performance & Tuning
WordCamp RVA 2011 - Performance & Tuning
 
5 critical-optimizations.v2
5 critical-optimizations.v25 critical-optimizations.v2
5 critical-optimizations.v2
 
Drupal 7 performance and optimization
Drupal 7 performance and optimizationDrupal 7 performance and optimization
Drupal 7 performance and optimization
 
Shootout at the PAAS Corral
Shootout at the PAAS CorralShootout at the PAAS Corral
Shootout at the PAAS Corral
 
WordPress Hosting Best Practices - Do's and Don't s | WordPress Trivandrum
WordPress Hosting Best Practices - Do's and Don't s  | WordPress TrivandrumWordPress Hosting Best Practices - Do's and Don't s  | WordPress Trivandrum
WordPress Hosting Best Practices - Do's and Don't s | WordPress Trivandrum
 
Caching 101 - WordCamp OC
Caching 101 - WordCamp OCCaching 101 - WordCamp OC
Caching 101 - WordCamp OC
 
Tuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy WorkloadTuning Linux Windows and Firebird for Heavy Workload
Tuning Linux Windows and Firebird for Heavy Workload
 
Presentation1
Presentation1Presentation1
Presentation1
 

Destacado

CBSib Core Pitch Module 1
CBSib Core Pitch Module 1CBSib Core Pitch Module 1
CBSib Core Pitch Module 1cnetbenson
 
Classification
ClassificationClassification
Classificationbigtb50
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHPThomas Weinert
 
Experiences With Pre Commit Hooks
Experiences With Pre Commit HooksExperiences With Pre Commit Hooks
Experiences With Pre Commit HooksThomas Weinert
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHPThomas Weinert
 
PHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPPHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPThomas Weinert
 
Indústria fonográfica: consolidação e reconfiguração
Indústria fonográfica: consolidação e reconfiguraçãoIndústria fonográfica: consolidação e reconfiguração
Indústria fonográfica: consolidação e reconfiguraçãoLucas Waltenberg
 
Transparencia 1 moderna
Transparencia 1 modernaTransparencia 1 moderna
Transparencia 1 modernaCiro Santos
 
Ensayo de ingrid administracion
Ensayo de ingrid administracion Ensayo de ingrid administracion
Ensayo de ingrid administracion carlos
 
TEMPORAL SANTANDER 18/ABRIL/12
TEMPORAL SANTANDER 18/ABRIL/12TEMPORAL SANTANDER 18/ABRIL/12
TEMPORAL SANTANDER 18/ABRIL/12samlasdi
 
Jaén+úbeda+baeza+viña, julio2010
Jaén+úbeda+baeza+viña, julio2010Jaén+úbeda+baeza+viña, julio2010
Jaén+úbeda+baeza+viña, julio2010lilianafigini
 
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...Universidad Autónoma de Barcelona
 
Lessons learned 5.0_produto_vfinal
Lessons learned 5.0_produto_vfinalLessons learned 5.0_produto_vfinal
Lessons learned 5.0_produto_vfinalJoao Horta
 
Projecte philipp
Projecte philippProjecte philipp
Projecte philippgmb22
 

Destacado (20)

CBSib Core Pitch Module 1
CBSib Core Pitch Module 1CBSib Core Pitch Module 1
CBSib Core Pitch Module 1
 
Classification
ClassificationClassification
Classification
 
Mobile App Development Made Easy
Mobile App Development Made EasyMobile App Development Made Easy
Mobile App Development Made Easy
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Experiences With Pre Commit Hooks
Experiences With Pre Commit HooksExperiences With Pre Commit Hooks
Experiences With Pre Commit Hooks
 
Open Data Hackathon - A How to Guide
Open Data Hackathon - A How to GuideOpen Data Hackathon - A How to Guide
Open Data Hackathon - A How to Guide
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHP
 
PHP 5.3/6
PHP 5.3/6PHP 5.3/6
PHP 5.3/6
 
FluentDom
FluentDomFluentDom
FluentDom
 
PHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPPHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHP
 
Indústria fonográfica: consolidação e reconfiguração
Indústria fonográfica: consolidação e reconfiguraçãoIndústria fonográfica: consolidação e reconfiguração
Indústria fonográfica: consolidação e reconfiguração
 
Transparencia 1 moderna
Transparencia 1 modernaTransparencia 1 moderna
Transparencia 1 moderna
 
Ensayo de ingrid administracion
Ensayo de ingrid administracion Ensayo de ingrid administracion
Ensayo de ingrid administracion
 
Relatorio.março.2012
Relatorio.março.2012Relatorio.março.2012
Relatorio.março.2012
 
TEMPORAL SANTANDER 18/ABRIL/12
TEMPORAL SANTANDER 18/ABRIL/12TEMPORAL SANTANDER 18/ABRIL/12
TEMPORAL SANTANDER 18/ABRIL/12
 
Manosabiertas
ManosabiertasManosabiertas
Manosabiertas
 
Jaén+úbeda+baeza+viña, julio2010
Jaén+úbeda+baeza+viña, julio2010Jaén+úbeda+baeza+viña, julio2010
Jaén+úbeda+baeza+viña, julio2010
 
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...
Despidos colectivos. Comentario a la sentencia del TS de 2 de diciembre de 20...
 
Lessons learned 5.0_produto_vfinal
Lessons learned 5.0_produto_vfinalLessons learned 5.0_produto_vfinal
Lessons learned 5.0_produto_vfinal
 
Projecte philipp
Projecte philippProjecte philipp
Projecte philipp
 

Similar a Optimizing Your Frontend Performance

Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdevChau Thanh
 
ASP.NET Scalability - DDD7
ASP.NET Scalability - DDD7ASP.NET Scalability - DDD7
ASP.NET Scalability - DDD7Phil Pursglove
 
ASP.NET Scalability - NxtGen Oxford
ASP.NET Scalability - NxtGen OxfordASP.NET Scalability - NxtGen Oxford
ASP.NET Scalability - NxtGen OxfordPhil Pursglove
 
ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonPhil Pursglove
 
Design a scalable site: Problem and solutions
Design a scalable site: Problem and solutionsDesign a scalable site: Problem and solutions
Design a scalable site: Problem and solutionsChau Thanh
 
20 tips for website performance
20 tips for website performance20 tips for website performance
20 tips for website performanceAndrew Siemer
 
High performance website
High performance websiteHigh performance website
High performance websiteChamnap Chhorn
 
Drupal performance
Drupal performanceDrupal performance
Drupal performanceGabi Lee
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling UpApache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling UpSander Temme
 
HPPG - high performance photo gallery
HPPG - high performance photo galleryHPPG - high performance photo gallery
HPPG - high performance photo galleryRemigijus Kiminas
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDPhil Pursglove
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Per Henrik Lausten
 
DrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an AfterthoughtDrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an AfterthoughtNick Santamaria
 
Silverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsSilverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsBrettTasker
 
Web performance mercadolibre - ECI 2013
Web performance   mercadolibre - ECI 2013Web performance   mercadolibre - ECI 2013
Web performance mercadolibre - ECI 2013Santiago Aimetta
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i Zend by Rogue Wave Software
 
Joomla Site Optimization
Joomla Site OptimizationJoomla Site Optimization
Joomla Site OptimizationPerry Wirth
 

Similar a Optimizing Your Frontend Performance (20)

Cache hcm-topdev
Cache hcm-topdevCache hcm-topdev
Cache hcm-topdev
 
ASP.NET Scalability - DDD7
ASP.NET Scalability - DDD7ASP.NET Scalability - DDD7
ASP.NET Scalability - DDD7
 
ASP.NET Scalability - NxtGen Oxford
ASP.NET Scalability - NxtGen OxfordASP.NET Scalability - NxtGen Oxford
ASP.NET Scalability - NxtGen Oxford
 
ASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG LondonASP.NET Scalability - VBUG London
ASP.NET Scalability - VBUG London
 
Design a scalable site: Problem and solutions
Design a scalable site: Problem and solutionsDesign a scalable site: Problem and solutions
Design a scalable site: Problem and solutions
 
20 tips for website performance
20 tips for website performance20 tips for website performance
20 tips for website performance
 
High performance website
High performance websiteHigh performance website
High performance website
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
Apache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling UpApache Performance Tuning: Scaling Up
Apache Performance Tuning: Scaling Up
 
HPPG - high performance photo gallery
HPPG - high performance photo galleryHPPG - high performance photo gallery
HPPG - high performance photo gallery
 
ASP.NET Scalability - WebDD
ASP.NET Scalability - WebDDASP.NET Scalability - WebDD
ASP.NET Scalability - WebDD
 
Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)Intro to XPages for Administrators (DanNotes, November 28, 2012)
Intro to XPages for Administrators (DanNotes, November 28, 2012)
 
DrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an AfterthoughtDrupalSouth 2015 - Performance: Not an Afterthought
DrupalSouth 2015 - Performance: Not an Afterthought
 
Drupal performance
Drupal performanceDrupal performance
Drupal performance
 
Web Performance Optimization (WPO)
Web Performance Optimization (WPO)Web Performance Optimization (WPO)
Web Performance Optimization (WPO)
 
Silverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsSilverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applications
 
performance.ppt
performance.pptperformance.ppt
performance.ppt
 
Web performance mercadolibre - ECI 2013
Web performance   mercadolibre - ECI 2013Web performance   mercadolibre - ECI 2013
Web performance mercadolibre - ECI 2013
 
Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i  Fundamentals of performance tuning PHP on IBM i
Fundamentals of performance tuning PHP on IBM i
 
Joomla Site Optimization
Joomla Site OptimizationJoomla Site Optimization
Joomla Site Optimization
 

Más de Thomas Weinert

Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHPThomas Weinert
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesThomas Weinert
 
The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your TemplatesThomas Weinert
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your TemplatesThomas Weinert
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend PerformanceThomas Weinert
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend PerformanceThomas Weinert
 

Más de Thomas Weinert (8)

Controlling Arduino With PHP
Controlling Arduino With PHPControlling Arduino With PHP
Controlling Arduino With PHP
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
Lumberjack XPath 101
Lumberjack XPath 101Lumberjack XPath 101
Lumberjack XPath 101
 
The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your Templates
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your Templates
 
SVN Hook
SVN HookSVN Hook
SVN Hook
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 

Optimizing Your Frontend Performance

  • 1. PHPNW09 Thomas Weinert Optimizing Your Frontend Performance
  • 2. About Me ● Application Developer – PHP – XSLT/XPath – (some) Javascript ● papaya CMS – PHP based Content Management System – uses XSLT for Templates
  • 3. How to scale you webpage? ● Hardware ● Backend ● Frontend
  • 4. Hardware ● More hardware ● Better hardware ● Moores Law – Transistors doubling every 18 months – Transistors != Performance ● Distributed systems are complex ● Think about environment
  • 5. Backend ● External data sources are slow – SQL – Files – Network ● Locking is slower ● Memory is faster – but less secure
  • 6. Mini/Micro Optimisations ● Myths – echo vs. print – ' vs. " ● Objects vs. functions vs. linear source ● Template systems
  • 8. Yahoo! ● Yahoo!'s Exceptional Performance team – Yahoo!'s Exceptional Performance team evangelizes best practices for improving web performance. They conduct research, build tools, write articles and blogs, and speak at conferences. Their best practices center around the rules for high performance web sites. – http://developer.yahoo.com/performance/
  • 9. Results ● 80% of the end-user response time is spent on the front-end.
  • 10. Firebug ● Firefox extension ● Analyze and manipulate – requests, page structure, CSS ● Javascript debugger
  • 13. HTTPFox ● Firefox Extension ● Log of all HTTP requests – Redirects – Cached requests
  • 14. YSlow ● Why (is your web page) slow ● Set of rules ● Firebug extension
  • 19. Google Page Speed ● Firebug extension ● CSS complexitiy
  • 20. Google Page Speed Screenshot
  • 21. Make Fewer HTTP Requests ● Combined files – CSS – JavaScript ● CSS sprites
  • 22. Combined files ● Release process ● CSS – Consider URLs ● JavaScript – Minify – Obfuscate
  • 23. CSS Sprites ● Elements with fixed size ● Background image ● Disable repeat ● Negative positions
  • 24. CSS Icons ● Raster of icons ● No repeat ● Fixed size <div> or <span>
  • 25. CSS Backgrounds ● Gradient ● Repeat in one direction
  • 26. Minify Javascript ● Most JS libraries provide a minified version ● YUI Compressor: http://developer.yahoo.com/yui/compressor/ – JS and CSS ● Packer – Webpage, .Net, Perl, PHP – http://dean.edwards.name/packer/
  • 27. #2 Use A CDN ● Content Delivery Network – Akamai Technologies – Mirror Image Internet – Limelight Networks ● Bring the content to your users – Geographic distance – Physics is still here ● Only for large sites ● Dynamic content is complex
  • 28. Headers ● Expires ● Cache-Control – Session-Management ● 304 Not Modified
  • 29. Expires ● Apache mod_expire ● ● <IfModule mod_expires.c> ● ExpiresDefault "access plus 1 month" ● ExpiresActive on ● </IfModule>
  • 30. Cache-Control ● None – no caching – default for sessions ● Private – cacheable in browser cache ● Public – cacheable in browser cache and proxies
  • 31. 304 Not Modified ● Send Etag and Modfication date – Etag: "some hash" – Last-Modified: Thu, 12 Sep 2008 11:00:00 GMT ● Request headers – If-Modified-Since: Tue, 12 Sep 2008 11:00:00 GMT – If-None-Match: "some hash" ● Response headers – HTTP/1.1 304 Not Modified
  • 32. Gzip Components ● Gzip != Zip – only compression – no packaging – tar.gz ● Good browser support – Accept-Encoding: gzip, deflate – Content-Encoding: gzip –
  • 33. Gzip in Apache ● mod_gzip ● mod_deflate – filter chain, works on dynamic content, too ● – http://httpd.apache.org/docs/2.2/mod/mod_deflate.html
  • 34. Gzip In PHP 5 <?php ob_start('ob_gzhandler'); ...
  • 35. Gzip In PHP 5 <?php if (function_exists('ob_gzhandler')) { ob_start('ob_gzhandler'); } ...
  • 36. Gzip Problems ● Not supported: – Transfer-Encoding: chunked – HTTP 1.0 client (old Squids)
  • 37. Configure ETags ● Browser still asks webserver ● Server specific – CDN – Load balancer with multiple servers ● Apache – FileETag none ● IIS – http://support.microsoft.com/?id=922733
  • 38. Split requests across domains ● HTTP 1.1 suggests 2 parallel requests per domain ● Separate content by function – www.domain.tld – themes.domain.tld – usercontent.domain.tld (security) ● Optimisation tools change the option ● Consider cookie domains
  • 39. Reduce DNS Lookups ● DNS maps host names to ips ● Needs time – 20-120 milliseconds ● Cached in browser
  • 40. Avoid Redirects ● Obviously addition requests ● Only cached with explicit headers ● http://www.domain.tld – → http://www.domain.tld/
  • 41. Put Stylesheets at the Top ● Progressive display of the page ● Page appears to load faster ● W3C specifications
  • 42. Put Scripts at the Bottom ● Scripts block parallel downloads – defer attribute in MSIE ● onload() event – used by most libraries ● Problem: document.write() – Counter – Banners
  • 43. Avoid CSS Expressions ● MSIE from version 5 – cross browser experience ● JavaScript inside CSS ● Evaluated – page render – resize – scrolling – mouse movements (hover)
  • 44. JavaScript And CSS Files ● Do not embed JS/CSS in your pages – No <script>...</script> – No <style>...</style> ● Seperate caching headers ● Revision parameter (style.css?rev=1234) – Get parameter – Unique URL for browser – Possibly in path/filename
  • 45. Remove Duplicate Scripts ● Team size ● Standard scripts – XMLRPC, JQuery, Prototype ● Script module for your template system ● $templatesystem->addScript('foo.js');
  • 46. Make Ajax Cacheable ● Often AJAX applications avoid caching – http://some.domain.tld/ajax.file?t=randomvalue ● A lot of requests ● Use more static URLs
  • 47. References ● Slides: http://www.a-basketful-of-papayas.net/ ● Yahoo Performance Team – http://developer.yahoo.com/performance/ ● Google Page Speed – http://code.google.com/intl/en-UK/speed/page-speed/ ● Apache GZIP – http://httpd.apache.org/docs/2.2/mod/mod_deflate.html ● No Etag in IIS – http://support.microsoft.com/?id=922733