Make your website fast. (And why you should).
scirra.com
scirra.com
"It's never a choice between two seconds and five seconds. It's a choice between two seconds and whenever the hell they come back to this tab, possibly never."
Many people go about web performance the wrong way, though. It usually isn't about algorithms, or hard work of any kind. It's mostly about rigorous preparation (a build process to combine and minify your assets) and outright lying (async loading, etc.).
I think a few things are changing though. The new Basecamp's speed is mind-blowing. One thing that interested me about their approach was that they claim to use static HTML whenever possible. This allows them to cache a single file and serve it to everyone.
So I may have to disagree with the age-old wisdom: "It’s important to keep your Javascript in external files where possible, since it allows the browser to cache the scripts and not load them on every page load!"
Why? With single-page apps I think we need to separate out "Javascript" into two categories: Actual code and templates. I've been playing around with the 37Signals approach, where I store the site-wide base template inside a script tag right in the body. Then I send a cache header the first time that HTML is requested to ensure it's only loaded once. Then page-specific (route-specific) templates and scripts are asynchronously loaded. So my actual "code" JS is still loaded with src="..." but templates aren't.
It's also easy to be fast when the functionality is so simple.
However, the single biggest speedup I ever got (on Wordpress) was in pushing MySQL onto a separate machine from the web server. Nothing else has come close in my experience.
And to add something constructive (besides a question) to the whole thing:
"Aggressive caches are best, with an incrementing querystring parameter at the end of them to force browsers to reload them when you make a change to them."
That is good. But even better is to include the version number in the filename (or path) itself: image.jpg?v=2 -> image_v1.jpg ... this doesn't throw some public proxies off and they cache your content that way. See this page for more details: http://code.google.com/speed/page-speed/docs/caching.html#Le...
edit: I would also like to see some article explaining how EXACTLY is google measuring our page load times. Because everything I've measured myself on our pages is fucking fast, but google seems to disagree (in order of magnitudes different results). The only logical explanation I've come up with is that google is measuring speed of our page from the states and our servers are in Slovenia. And that means that the page is super fast for our Slovenian users (which are the only one that matter since it is a local page) but slow for google who is way over there on the other side of Earth. This really pisses me off to be honest since there is only so much I can do and we are being punished (as in lower rankings due to speed) for not following some rules that we don't know.
I beleive you can do more, for example if you start looking:
- DNS (I don't know too much about this though)
- How the web server handles the requests (I saw a post here on HN about this recently but can't find it where MS/Google change some deep settings to improve loading time)
- Preloading pages by guessing users next page choice
All are quite difficult to execute however and provide diminishing returns over making sure you have all the fundamental things set up correctly.
I'm looking into that yes.
On Linux - http://www.cdnplanet.com/blog/tune-tcp-initcwnd-for-optimum-...
On Windows - http://www.andysnotebook.com/2011/11/increasing-the-tcp-init...
I also think they are possibly counting Tweet button/g+1/Facebook frames in the time which is wrong in my opinion as these are such small fragments on a webpage yet are often responsible for a large percentage of the load time (for us it is up to 50%!)
Also I think that if you have video (at least flash, since that's what we have) or games, that then google times the amount of time it takes for the complete video/game to load. Which is complete madness considering that the video/game is playable long before it's fully loaded. But I can't say that it really does that since I have no way of knowing :/ But I do think that you are correct on the widgets part.
Then make a HN post about it.
Just a note - if you are using django, use django-mediagenerator. With a little bit of configuration, you can take care of quite a few of the easy wins - it will combine jslib1.js, jslib2.js, jslib3.js into jslib-<hash>.js and minify it (if you ever modify jslib2.js, the hash will change, of course).
Hitting only these easy wins shaved about 250ms off my page load time.
http://www.allbuttonspressed.com/projects/django-mediagenera...
http://torbit.com/blog/2011/05/31/localstorage-mobile-perfor... http://torbit.com/blog/2011/05/02/webp-statistics/ http://torbit.com/blog/2011/11/17/a-better-way-to-load-css/
Suggestions on how to speed up your website is only about half the content, I thought it was worth posting because it also looked at why you should do it in more detail as well.
This was a very well structured and thought out article. It is actually identical to an article I have been wanting to write for a while. Few things I might have added as an addition, being that while the spec notes 2 open connections per host, most browser these days allow considerably more.
> Chrome allows 6 connections per hostname > FF allows 6 connections per hostname Even the iPhone allows 4 connections per hostname.
Good job on the article. Exactly as you say, even if one person doesn't find it useful, doesn't mean other people share the same sentiments!
ie, RFC 3390 ( http://www.rfc-editor.org/rfc/rfc3390.txt ), provides algorithms for determining/detecting the maximum initial window for TCP traffic.
min (4MSS, max (2MSS, 4380 bytes))
Just a few lines later the spec specifically says that:
> "This change applies to the initial window of the connection in the > first round trip time (RTT) of data transmission following the TCP three-way handshake."
Well, guess what, lots of large companies ignore this, and they start with a much larger initial window. They do this in order to shave off as many round trips as possible, to reduce your load time. (Google AMZ Apple etc)
This spec was written 10 years ago! (Read here for more information http://blog.benstrong.com/2010/11/google-and-microsoft-cheat... )
What about just post-deploy hooks with your preferred version control software? Identify your CSS/JS, add a current time+date?
I think I am just going to bite the bullet and go through everything I have ever written and wrap it in some "CDN"izer, method to easily include version number.
Also wrt the article, http://www.scirra.com/blog/74/making-a-fast-website, won't naive bottom loading all your JS lead to them being serialised and thus cost you in page load time?
Also if your JS modifies the DOM tree shouldn't it arrive earlier so as to prevent reflows and such?
See eg http://code.google.com/speed/page-speed/docs/rtt.html#PutSty...
> Also if your JS modifies the DOM tree shouldn't
> it arrive earlier so as to prevent reflows and such?
And what will it modify, if DOM has not arrived yet?
Javascript on top can block other components from loading, hence the recommendation.http://www.stevesouders.com/blog/2012/02/10/the-performance-...
Octopress will generate static HTML and use Disqus for comments: http://octopress.org/
S3 added the ability to serve an index.html file a while ago: http://www.allthingsdistributed.com/2011/02/website_amazon_s...
Cloudflare will be your DNS host and CDN in one: http://www.cloudflare.com/ (they also have a lot of other fun features)
I tried Amazon's Cloudfront too, but they aren't as great with hosting static files. (especially index.html data in subfolders seem to error out for me).
We also use Octopress to run a german-language podcast (http://blog.binaergewitter.de/). Adding the iTunes feed and flatter support wasn't all thaaat hard. Although I still think the liquid template system is kinda weird. (Our "Octopod" fork is here: https://github.com/Binaergewitter/binaergewitter.github.com/... , not 100% reusable though)
The first step in losing weight is stepping on a scale.
Edit: working now
Should I use CNAME alias or direct A entries for those static0 ... static3 hostnames ?
i don't have exact figures by hand, but one sites (which used sprits very very heavily) we managed to save about 250ms in DOM rendering - on some slow, crappy, ugly plattforms (not talking about IE6 here, but IE7 and 8 aren't much better in that regard).
i recommend using chrome speed tracer extensively for DOM rendering optimization. what is just a little bit slow in chrome is unbelievable slow on IE.
My business has content that users can freely embed on external sites; it's dynamic locally, but served up static (15 minute refreshes) off of Rackspace Cloud Files CDN for the embed. The cost to serve 1 billion widgets on AWS came out to $1,236 due to the transaction costs, but on Rackspace (which has compression with Akamai and no per transaction cost)it got down to $180, which is insanely cheap for serving a billion widgets.
I agree with you on CDN's, I was in two minds which direction to take with the article as my original title was going to be along the lines of "... without spending any more money". I think using your own subdomains over a CDN is often more beneficial to startups as they save money, although it will cost a little at first in time.
Also admittedly I've very little experience with commercial CDN solutions (but this will change soon I think) so didn't feel confident enough to write about it.
I'd recommend you give Rackspace a try. You can sign up for their CDN for free; they hit you for the storage and bandwidth used, but not per transaction. It's worth just experimenting with in a very simple manner to get familiar with (small text files, css files, and so on). Rackspace has a very convenient web based control panel for moving a smaller number of files into their CDN (and of course APIs).
Amazon's Cloudfront is excellent from the standpoint that you don't need to programatically upload any files into it, Amazon can absorb them to their CDN and then serve the files up thereafter (you just create a dns entry for Cloudfront, like cdn.mysite.com and use the same url structure you would on mysite.com). With Rackspace you have to get the files into their cloud, which can be inconvenient if you're talking huge numbers of individual files.
For less than $5 you can absolutely learn everything a developer would need to know about both of those offerings through experimenting with them.
I've had some quotes from expensive CDN's starting from $200p/m, do you have any experience with these type? Are they better?
We looked at Cloudfront but they don't have an Australian distribution point. In the end we went with EdgeCast (via GoGrid).
Originally we were with Voxel, but they've had a couple network issues in the past month (result of DDoS attacks I think).
As far as speed, they were among the best as far as we were able to test. There are lots of variables involved though that make it kind of hard to compare - how long things stay in the cache at the edge vs. your traffic patterns, etc.
The same data for most of them, or do they all change?
You might could hash the file contents, add some part of the hash to your deployed file name, and then use that hash to refer to the changed files.
It's also dead easy to set up -- you used to have to use S3 for the backend, but now you can have it refer to any server. So you could make cdn.example.com simply pull content from www.example.com and then just replace "www" with "cdn" in your img src's and you're done.
It's also free - and besides making your site faster, also blocks a lot of the spam you would normally see.
Just last week, their anycast servers in Chicago blocked all traffic and said my server was down even though it wasn't.
It took them about 3 days to fix it, so I am a bit skeptical about using them in a production environment.