How Google uses HTML5 to reduce startup latency for mobile Gmail
googlecode.blogspot.com
googlecode.blogspot.com
<script id="lazy">
// Make sure you strip out (or replace) comment blocks in your JavaScript first.
/*
JavaScript of lazy module
*/
</script>
<script>
function lazyLoad() {
var lazyElement = document.getElementById('lazy');
var lazyElementBody = lazyElement.innerHTML;
var jsCode = stripOutCommentBlock(lazyElementBody);
eval(jsCode);
}
</script>
What if my JavaScript code looks like this:var x = "hello /* world */";
I wouldn't do it this way. Instead just bundle all your code into a single file and optimize its caching. No HTML5 needed: use HTTP headers.
> On an iPhone 2.2 device, 200k of JavaScript held within a block comment adds 240ms during page load, whereas 200k of JavaScript that is parsed during page load added 2600 ms. That's more than a 10x reduction in startup latency by eliminating 200k of unneeded JavaScript during page load! Take a look at the code sample below to see how this is done.
But once again this is an issue of when to eval the code, not when to load it. Put the script tag at the end of the page, so that it gets eval'ed after most of the page is already built.
The chip on an iPhone runs at what, 600 MHz, maybe 800 MHz? My Apple II ran at 1 MHz. I was counting bytes then. I hope I'll see a day where I don't count bytes anymore :-)
And the title is wrong - they are not using HTML5 to do anything, it's about how to reduce latency by lazy loading modules in the background.
In the article they're mostly using 'HTML5' to mean 'not flash' and 'not native'.
But you can't really have HTML5 without HTML, just as you might write about C tricks in a Objective-C or Cocoa article.