23rd February, 2011 - Posted by david
When I was working on rebuilding daft.ie’s mapping system for the modern web, it involved writing alot of Javascript (JS) code and loading this via a couple of JS source files, one external one from Google (i.e. the core Google Maps JS) and another from our own web-servers.
It all worked fine in most browsers, except of course Internet Explorer (IE). To be fair, IE8 was fine; however, seemingly at random, the zoom control would sometimes not appear on the map for IE7 and IE6 and you’d get one of IE’s very unhelpful error messages. At Daft we like to ensure that the site is available and consistent on all browsers, so it was imperative to get this issue sorted.
Because of the aforementioned unhelpful error messages, it proved to be a very difficult bug to nail down. I began to suspect that it was due to the code from Google loading after the map is set-up in the daft.ie hosted file, i.e. IE was calling Google-specific functions before it had the code. As it was all wrapped in a jQuery $(document).ready
I didn’t think this could happen, but turns out that in the older versions of IE it could! I tried moving the JS around, loading the Daft-specific JS as late as possible, to try and give the Google JS the maximum amount of time to load, but that was to no avail.
So, I needed to find a way to load the Daft JS when I was 100% certain the Google JS had arrived. After various futile attempts, the solution ended up being pretty simple – change my
1
| $(document).ready(function() { |
to
1
| $(window).bind("load", function() { |
That way, the bulk of my JS is only executed once everything else has loaded and sure enough, the issue disappeared!
Read more...
25th January, 2011 - Posted by david
Today I read an interesting article on Google’s Webmaster Central blog about planned down time, for maintenance or whatever. Basically, you need to communicate to users and potential site-crawlers/indexers that the site is down, but it’s ok, it’ll be back up soon!
My suggestion would be to do a mod-rewrite (if using Apache, but other web servers have equivalents) on all incoming files to your 503 file, something like
RewriteRule ^(.*)$ 503.php [L]
If you put this rule first, you can leave the rest of your rules where they are as the “L” at the end of the line tells Apache that this is the last rule it needs to process, i.e. it can ignore the others.
Then, in your 503.php
you need to tell any web-crawlers/site-indexers that the service is down but will be back at a certain time using PHP’s header
function, as well as telling your users the same using a plain simple descriptive paragraph:
<?php
$back = 'Tue, 1 Feb 2011 12:00:00 GMT';
// tell any web-crawlers
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Retry-After: '.$back);
// calculate time to wait for users (I assume here it'll only be a matter of hours)
$vals = array('hour' =--> 3600, 'minute' => 60, 'second' => 1);
$back_in_seconds = strtotime($back) - time();
$back_text = '';
foreach ($vals as $key => $time) {
$cur_time = floor($back_in_seconds / $time);
if ($cur_time) {
$back_text .= $cur_time.' '.$key;
if ($cur_time != 1) $back_text .= 's';
$back_text .= ', ';
$back_in_seconds %= $time;
}
}
$back_text = rtrim($back_text, ', ');
?>
<!--- etc. ---->
We are currently undergoing scheduled downtime to upgrade the site.
We'll be back in <!--?= $back_text ?-->. Thanks for your patience.
<!-- etc. -->
Should all be pretty straight-forward, but it’s good to let people know that you know you’re down and when you expect to be back.
Read more...