Policy 1 ● Start when you need, from most effective point – “premature optimization is the root of all evil” (Donald Knuth) – the law of the instrument: “Give a small boy a hammer, and he will find that everything he encounters needs pounding.” (Abraham Kaplan)
Policy 2 ● Understand pros and cons of your improvement – Optimization may make your product and/or build system complex ● e.g. JS/CSS Minification, CSS Image Sprites – Is it enough simple for long-life system? Tricky solution may make maintenance difficult.
Policy 3 ● Make your improvement evaluable – Do not guess, just measure and verify it. – Use objective evidence to evaluate your page. ● When does DOMContentLoaded event fire? ● When does load event fire? ● Is there any other good objective evidences?
Basic knowledge ● To build hypothesis, learn general examples and best practices – High Performance Web Sites (O'Reilly) – Even Faster Web Sites (O'Reilly) – High Performance JavaScript (O'Reilly) – Web Performance Best Practices – Yahoo!'s Exceptional Performance
What is problem? ● 'Wait' means that browser waits response from server. – Latency problem: server is too far from client ● 'Receive' means that browser receives data from server. – Too much data to download
Which data is so huge? ● JavaScript and Image are heavy – JavaScript: 5 files, 144.4 KiB – Image: 49 files, 593.2KiB – YSlow reported that content isn't gzipped – jquery.js (105.3 KB) is the biggest resource
Does browser cache works? ● You can see that it still has requests and 304 response. – YSlow reported that static components has no far-future expiration date. ● Browser should ask server that are there any updated resources or not. – Latency problem makes this problem severe.
Problem ● Controlable – JS/CSS is not gzipped – Size of images are too heavy – No expiration date in HTTP response ● Uncontrolable – Latency ● to solve, we need new server or CDN
Solution 3: mod_expires ● Add expiration date to HTTP response header. – Reduced requests from 57 to 2 (HTML and Google Analytics). – Good improvement for high latency environment. ExpiresActive on ExpiresDefault "access plus 1 day"
Appendix: What is F5 (reload)? Send request to download resources? Use browser cache? Clear cache Yes No F5 (reload) Yes Yes if result is 304 Enter at address bar No if cache isn't expired Yes ● If you want to reproduce first access, you need to clear cache and cookie. ● If you want to reproduce second access, you need to use not F5 but enter at address bar.