Web Performance for PHP Developers
New York, NY
June 16th, 2009
What is performance?
- Performance is how fast your site works
- NOT how many users it can serve (Scalability)
- NOT how often it's down (Reliability)
Why do we need to care?
- User experience
- Money!!!
- +100ms → -1% sales (Amazon) *
- +400ms → -5-9% full-page traffic (Yahoo! Autos front page) **
- +500ms → -20% searches (Google) ***
Part 3: Front-end performance testing and optimization
Sergey Chernyshev
How do we know what's going on?
- YSlow for Firebug
- Google's Page Speed is new, but promising (also Firebug extension)
- Waterfalls:
- JS profilers
- CSS analysis
Amazon Waterfall!
- Total Requests: 88
- Total Time: 6.344 seconds
- Back-end Time: 0.968 seconds = just 15%
CNN Waterfall!
- Total Requests: 174
- Total Time: 4.406 seconds
- Back-end Time: 0.171 seconds = less then 4%
Make fewer requests
- Consolidate your JS & CSS
- on the fly using PHP
- just create simple build process (it can be manual!)
- Use fewer images:
- try CSS instead
- use CSS sprites for background images
Flush early
- Flush your header early - browser will start download before backend is done
ob_flush();
flush();
Fight with cache, not against it
- DO NOT put random number in the URL just to avoid "browser caching problem"
- It's not a problem, It's a feature!
- If you know how to use it
Cache is your friend
- Modern web servers are already smart and send Last-modified header by default for all static content (JS, CSS, images)
- so browsers can use conditional GET (If-Modified-Since => 304)
- But they are not smart enough to automatically use cache expiration headers
Cache is your friend
- Use far future expires on all static content to avoid pointless 304s!
Cache is your friend
- Use far future expires on all static content to avoid pointless 304s!
Cache is your friend (even for dynamic content)
Q & A