Posts from July 2009

Get Your API Right

A great post by Trek Glowacki with 8 tips on creating an API. My favorites are #2 - Use Your Verbs and #4 - Use Your Status Codes. It’s amazing how much simpler an API can be if you integrate basic REST principles, and if you’re using Rails, it’s super easy to do.

Posted on July 8, 2009 Leave a Comment
Tagged with: , ,

Haml/Sass 2.2 Released

Haml/Sass 2.2 was released today, and it’s got a lot of great new features. While I’ve never tried Haml, I use Sass for this site, and I can’t wait to try out 2.2. My favorite update: mixins with arguments

Posted on July 8, 2009 Leave a Comment
Tagged with: , , , , ,

Boston to debut an iPhone app for municipal complaints

Brilliant idea:

City officials will soon debut Boston’s first official iPhone application, which will allow residents to snap photos of neighborhood nuisances - nasty potholes, graffiti-stained walls, blown street lights - and e-mail them to City Hall to be fixed.

This could prove to be really intelligent–the city doesn’t have to employ as many people checking for problems, since anyone with an iPhone can now snap a picture and send it to be fixed.

Posted on July 6, 2009 Leave a Comment
Tagged with: , ,

4 Easy Frontend Optimizations for Your Site

Over the past few weeks, I’ve been tweaking the site a bit to help speed up page loads. After running YSlow and Page Speed, it seemed like the slowest aspects of my site weren’t necessarily happening behind the scenes with my Ruby code, but rather on the frontend with images, Javascript, and CSS. Below, I’ve listed four ways you can squeeze more speed out of your site without even touching backend code.

Gzip your files

One of the first things I did to speed up my site was to start using mod_deflate to gzip compress data from my site before it’s even sent to the viewer’s browser. Basically what happens is after my Rails app returns the HTML for the page, Apache then compresses it and sends the compressed version to the user. Enabling this brought my front page size down to 6KB from around 22KB, a 73% improvement! You should enable this on all of your plaintext files, such as external CSS and Javascript files, as well as any HTML that’s being sent to the browser–essentially as many files as you can get away with.

For more information, make sure to read Paul Stamatiou’s excellent post on mod_deflate, where he goes through the steps of gzipping your site on Apache.

Set a far future expires header for images, stylesheets, and JS

When your browser wants to fetch a file, it first checks to see if it’s stored in its local cache, and if it has a new enough version of the file, it will display that instead of taking the time to download it from the server. The problem is, how does your browser know if the cached version is “new enough”? The trick is to use the Expires header for any files you know aren’t going to change very often (such as images, stylesheets, and javascript). I did this on all of my photos, and it has made a huge difference–after turning on the header, my bandwidth usage went down by 70%, since browsers were no longer re-requesting images they already had.

For how to set a far future expires header with Apache, check out Christian Johansen’s tutorial on the subject.

Load Javascript Libraries from Google

Nowadays, just about every site is using a javascript library of some sort, whether it’s Prototype, jQuery, or something else. Since the library might not change from site to site, why not leverage that to cut down on download times? Google has done the work for you, with their AJAX Libraries API, which provides you with a CDN-hosted version (what is a CDN?) of popular JS libraries, so they’re super fast, and once your browser downloads the library for the first time, it will be retrieved from cache for any site that uses the same file.

There are 2 ways to use Google’s hosted libraries, via the API listed on their page or just by including the file. For instance, I’m including jQuery 1.3.1 with this code:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>

I’m not sure exactly how much faster this has made my site, but it definitely keeps bandwidth usage down and makes the user experience much quicker.

Defer Loading of Stat-tracking Javascript

I’ve always run two separate stat tracking scripts on this site: Google Analytics and Mint, but recently, I really started to notice they were slowing down page loading time (especially with Mint). To combat this, I decided to defer loading the scripts until after the page has finished, so as to ensure they don’t impact the user experience negatively. To do this, I just used jQuery’s $.getScript() function like this:

$(document).ready(function() {
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  $.getScript(gaJsHost + 'google-analytics.com/ga.js', function() {
    var pageTracker = _gat._getTracker("GOOGLE TRACKING CODE");
    pageTracker._initData();
    pageTracker._trackPageview();
  });
  $.getScript('http://path/to/mint/?js');
});

Just customize it to point at your stat tracking scripts, and you’re ready to go. One caveat with this–it may impact your stats, because scripts won’t be loaded until the page finishes rendering, meaning if someone clicks off the page before them, it might not register their visit. I haven’t had enough time to see if my decision to defer loading has affected my stats, but I’m guessing it would have at least a minor impact.

Anything else?

Is there anything else you’ve done for your site that’s really lowered your loading times? Let me know in the comments!

Posted on July 4, 2009 Leave a Comment
Tagged with: , , , , , , , ,

Ant mega-colony takes over world

Attack of the ants?

In Europe, one vast colony of Argentine ants is thought to stretch for 6,000km (3,700 miles) along the Mediterranean coast, while another in the US, known as the “Californian large”, extends over 900km (560 miles) along the coast of California. A third huge colony exists on the west coast of Japan.

While ants are usually highly territorial, those living within each super-colony are tolerant of one another, even if they live tens or hundreds of kilometres apart.

Creepy–billions of ants, working together? Sounds like a science fiction film.

Posted on July 3, 2009 Leave a Comment
Tagged with: , , ,

LRO's First Photos of the Moon

The Lunar Reconnaissance Orbiter (LRO) recently sent back its first photos of the moon, which you can see over at Bad Astronomy. What’s remarkable is how good the resolution on the photos is:

This image, taken in the Mare Nubium region of the Moon, shows a heavily cratered area. The scale here is amazing: the whole image is 1400 meters across, or just under a mile. That’s like looking out your airplane window… if you were over the frakking Moon!

When LRO settles into its final orbit, it will be able to resolve objects only 18 inches across. I can’t wait to see the shots of the Apollo landing sites (which I mentioned earlier).

Posted on July 3, 2009 Leave a Comment
Tagged with: , , , , , , ,