5. A *rough* guide....
General principles for you to take and build
on
3 tips for loadtime performance
3 principles for speedy runtimes
6. A *rough* guide....
General principles for you to take and build
on
3 tips for loadtime performance
3 principles for speedy runtimes
Seconds, not milliseconds (possibly...)
19. Some facts of life
HTTP requests are expensive
Browsers are single threaded (ignoring
web workers)
20. Some facts of life
HTTP requests are expensive
Browsers are single threaded (ignoring
web workers)
2-4 resources downloaded in parallel per
host
21. Some facts of life
HTTP requests are expensive
Browsers are single threaded (ignoring
web workers)
2-4 resources downloaded in parallel per
host
<script> tags disable parallel downloads
and block all rendering below them
34. Concatenation
Less HTTP requests === :-)
But... rarely used scripts may be better off
loaded where appropriate.
Automate: Sprockets, php-sprockets etc
38. Minification
Strips whitespace and comments out,
shortens variables in functions
Minify, don’t Pack!
Anything that obfuscates code and requires
eval’ing has a performance hit. Avoid!
41. GZip your JS!
GZip is the way forward. Use it.
Can reduce file size by up to 70%
42. GZip your JS!
GZip is the way forward. Use it.
Can reduce file size by up to 70%
No whitespace removal or variable alteration
- easy to debug
43. GZip your JS!
GZip is the way forward. Use it.
Can reduce file size by up to 70%
No whitespace removal or variable alteration
- easy to debug
Configure once and forget about it, all taken
care of by the server
44. GZip your JS!
GZip is the way forward. Use it.
Can reduce file size by up to 70%
No whitespace removal or variable alteration
- easy to debug
Configure once and forget about it, all taken
care of by the server
49. Dynamic scripts
Add <script> tags via DOM methods to
avoid blocking of other page processes
Only FF and Opera guarantee execution
order (concatenation can help with this)
50. Dynamic scripts
Add <script> tags via DOM methods to
avoid blocking of other page processes
Only FF and Opera guarantee execution
order (concatenation can help with this)
Use onload callbacks to tell us when it’s
loaded, can nest to ensure execution order
is respected
64. About that DOM...
The DOM is a language independent API for
working with XML/HTML documents.
65. About that DOM...
The DOM is a language independent API for
working with XML/HTML documents.
The JS engine and the DOM are implemented
separately in browsers.
66. About that DOM...
The DOM is a language independent API for
working with XML/HTML documents.
The JS engine and the DOM are implemented
separately in browsers.
Every time you touch the DOM you incur a
performance penalty.
85. Caching is King!!
Use GET requests
Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
86. Caching is King!!
Use GET requests
Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
Ensure appropriate headers are sent by the
server
87. Caching is King!!
Use GET requests
Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
88. Caching is King!!
Use GET requests
Tailor URLs to the user where possible:
http://mydomain/ajax/info.php?
user_id=129473
Ensure appropriate headers are sent by the
server
(ie. a far future Expires header)
91. Be smart about return data
HTML > JSONP > JSON > XML
Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
92. Be smart about return data
HTML > JSONP > JSON > XML
Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
JSONP - no parse time, already in a native
format
93. Be smart about return data
HTML > JSONP > JSON > XML
Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
JSONP - no parse time, already in a native
format
JSON - needs parsing/evaluating first
94. Be smart about return data
HTML > JSONP > JSON > XML
Return HTML wherever possible - templating
in JS is slow, your server is fast, use it!
JSONP - no parse time, already in a native
format
JSON - needs parsing/evaluating first