Why are pages slow?(themvcblog.typepad.com) |
Why are pages slow?(themvcblog.typepad.com) |
The particular scenario where we saw network-loading of resources consistently being faster was on first load of a frequently viewed page. In this scenario we found that loading certain scripts and images from cache (which we inferred to be physical disk because it was 'home page' activity) was slower for a significant portion of the experiment group than loading from the network. In this context loading from 'network' meant either a hot HTTP request to a CDN or inlining small images and scripts directly in the HTML on every single request.
As I mention above, it's worth regularly re-evaluating assumptions. I'd bet that the big CDN players have a huge presence in New Zealand and Australia, given the latency, cost of ingress and density of the actual population centres.
And who cares about the "guy from New Zealand"? You optimise to the markets/areas you target.
The solution has been to serve static HTML, i.e. the index page of the single page app part, with a one hour cache expiration and links to other static resources (JavaScript, CSS, images etc.) decorated with their E-Tag and loaded from a CDN. For non static pages the set up is the same, but the caching time is lower. The static resources have far off (one year or so) expiration headers so are cached permanently.
By using a CDN for all your assets you can reduce a 200ms roundtrip to 8ms for all users worldwide, bringing the page loading time to way below 200ms with an empty cache and well below 100ms with a primed cache since you still need to do an XHR to check the login status.
Small time saving tip: if you go with CloudFront, go all out and use all edge locations - it's cheap. I tried using Europe only at first only to eventually find out that I was still being given an edge location in the US despite being in Finland.
On a serious note: I think Opera Dragonfly is also a great tool for this providing even more information.