Tag Archives: blogging

What you read in 2010: top posts on ITWriting.com

With three days to go, traffic on ITWriting.com in 2010 is more than 50% up over that of 2009 with over 1 million unique visitors for the first time. Thank you for your attention in another crazy year in technology.

So what did you read? It is intriguing to look at the stats for the whole year, which are different in character from stats for a week or month. The reason is that over a short period, it is the news of the day that is most read – posts like The Java Crisis and what it means for developers. Over the year though, it is the in-depth technical posts like How to backup Small Business Server 2008 on Hyper-V that draw more readers, along with those posts that are a hit with people searching Google for help with an immediate problem like Cannot open the Outlook window – what sort of error message is that?

The most-read post in 2010 though is in neither category. In July I made a quick post noting that the Amazon Kindle now comes with a web browser based on WebKit and a free worldwide internet connection. Mainly thanks to some helpful comments from users it has become a place where people come for information on that niche subject.

On the programming side, posts about Microsoft’s changing developer story are high on the list:

Lessons from Evernote’s flight from .NET

Microsoft wrestles with HTML5 vs Silverlight futures

Microsoft’s Silverlight dream is over

Another post which is there in the top twenty is this one about Adobe Flash and web services:

SOA, REST and Flash/Flex – why Flash does not PUT

along with this 2009 post on the pros and cons of parallel programming:

Parallel Programming: five reasons for caution. Reflections from Intel’s Parallel Studio briefing

This lightweight post also gets a lot of hits:

Apple iPad vs Windows Tablet vs Google Chrome OS

It is out of date now and I should do a more considered update. Still, it touches on a big theme: the success of the Apple iPad. When you take that alongside the interest in Android tablets, perhaps we can say that 2010 was the year of the tablet. I first thought the tablet concept might take off back in 2003/2004 when I got my first Acer tablet. I was wrong about the timing and wrong about the operating system; but the reasons why tablets are a good idea still apply.

Watching these trends is a lot of fun and I look forward to more surprises in 2011.

Speeding page load with dynamic JavaScript

I’m delighted that ITWriting.com is sufficiently popular to sustain some advertising. I’m not pleased though with the impact on performance. The problem is that ads such as those from Google Adsense or Blogads are delivered by remote scripts. It usually looks something like this in the HTML:

<script type="text/javascript"
  src="http://some/remote/script.js">
</script>

When the browser encounters this script, it stops and waits until the script returns. This means that your site’s performance depends on the performance of the site serving the script. At times I’ve noticed significant slowdown – though to be fair, Google is normally faster than most others in my experience.

So how can this be fixed? I’ve spent some time on the problem, but with limited success. Ideally I’d like an Ajax-y solution where the ads flow in after the rest of the page had loaded and rendered, because the content is more important than the ads. The first step though is to place the scripts at the end of the page, so that the rest of the content is downloaded first. However, the ads have to appear towards the top of the page, otherwise the advertisers will not be happy. I tried inserting the script dynamically like so:

var addiv = document.getElementById("addiv"); //where the ad is  to appear
var theScript = document.createElement("script");
theScript.type="text/javascript";
theScript.src = "http://some/remote/script.js"; 
addiv.appendChild(theScript);

While this works after a fashion, it does not do the job. The problem is that the script typically calls document.write. If you are lucky, the ad will appear at the bottom of the page. If you are unlucky, the ad will replace the entire page.

What I needed to do is to capture the output sent to document.write and then insert the HTML dynamically. It turns out that JavaScript makes this easy. We can simply override document.write with our own function. Like so:

var addiv = document.getElementById("addiv"); //where the ad is  to appear
var adHtml = ”;
var oldWrite = document.write;
document.write = function(str)
{
    adHtml += str;
}
<script type="text/javascript"
  src="http://some/remote/script.js">
</script>
document.write = oldWrite;
addiv.innerHTML = adHtml;

This is brilliant, and in fact works perfectly for some of my ad scripts. Unfortunately it does not work for the slowest performer. The problem is that I have no control over the content of the remote script. In the non-working case, the remote script does not return HTML. It returns another script, which references another remote script. Now I have to figure out how to handle all the possible cases where scripts return scripts, which might or might not call document.write.

I’d be interested if anyone has a generic solution. There is a library here that looks like it might be helpful.

Another reflection is that it is in the interests both of advertisers and publishers to have scripts that execute fast and/or behave in a predictable manner that is friendly towards deferred loading techniques. It is no use writing convoluted code to deal with a particular script, when it might change at any time and break the site.

A note to RSS subscribers

This blog has a full-text RSS feed. In other words, you can read the entire contents of a post without visiting the site – though I hope you will visit the site from time to time to read the comments, like the excellent discussion on web vs desktop applications here.

The reason for this note is that the feed broke for some subscribers recently; and the reason it broke was that I’d hacked the code to ensure that you get full text feeds and not excerpts with a “read more” link. I had hacked the code not because WordPress was broken exactly, but because of a legacy problem. The feed for this blog used to be http://www.itwriting.com/blog/rss.php. WordPress still supports this URL, but without my hack it delivers excerpts, even though WordPress is set for full text. The hack works; but it is perilous because I use Subversion to keep WordPress up-to-date. If I modify the WordPress source, and then the same file gets updated in the official source, then Subversion inserts some stuff in the file to assist in resolving the conflict. That’s fine, except that it may break the PHP until I get round to fixing it. There’s also a risk that the modified file will no longer work because of changes elsewhere.

The sane solution then is not to modify the WordPress source, but to ask you to use the modern, approved and up-to-date RSS feed URLs which are:

http://www.itwriting.com/blog/feed for RSS

and

http://www.itwriting.com/blog/feed/atom

for Atom.

If you use Google Reader, for example, I suggest you remove the existing subscription and add a new one with one of the above URLs.

That said, the old URL now works again, but with excerpts and not full text. The reason is not that I want you to visit the site, add to my page views and enjoy the unobtrusive advertising (though I do); it’s because of the technical issue above. Now you know how to fix it.

Fixing a WordPress plugin setting

I changed the theme and plugins used on this blog recently. Along the way I managed to slightly corrupt the settings for one of the plugins, GD Star Rating, the result being that the stars in the Top Rated Posts widget would not display. I figured out the problem: the plugin stores the path to the graphics which represent the stars, and this had incorrectly been set to an https path. Since I use a self-generated SSL certificate, the result was that browsers did not trust the connection and refused to display the graphics.

Unfortunately this path is not configured directly in the plugin options, as far I can see. I temporarily changed it to display a text rating while I worked out how to fix it.

The setting had to be in the MySQL database somewhere; and I found it. It is one value in a massive 10,000 character field called  option_value, in the main options table. It seems that most of the settings for the plugin live in this single colon-separated field, even though the plugin also creates 12 tables of its own for the ratings data. Hmm, I don’t like the way this implemented. How often does this field get queried and parsed?

Still, the immediate problem was to alter the value. I ran up the MySQL interactive SQL utility and typed very carefully. This is where one false move can obliterate your WordPress install; I’m reminded of someone I knew (not me, honest) who set all his company’s customers to have the same address with a careless update missing its WHERE clause. Fortunately this is only a blog. Transactions are also good. Anyway, what could go wrong? it was a simple combination of UPDATE, REPLACE and WHERE.

It worked, the stars have returned, and I know a little bit more about the innards of WordPress and this particular plugin.

Seven years of blogging, and a redesign

This blog began in 2003, though the website goes back to 2000, and I now see little difference between what is now a blog, and what in 2000 was a more painful process of authoring web content, especially with the decline of RSS readers. Still, my first blogging efforts were powered by a now-defunct project called bblog. I modified this heavily to add features and cope with comment spam – almost non-existent in 2003 – and then in 2006 accepted that I would be better off with a mainstream blog engine and selected WordPress, which has exceeded my expectations.

When I moved to WordPress I picked a theme which met my requirements, then modified it to tidy up the layout and to support non-intrusive advertising. I found myself to some extent boxed in once again, since I could not change or upgrade the theme without losing my modifications. This also meant I was missing out on newer features of WordPress. Widget support is a breakthrough feature, letting you add features to the site through a simple drag-and-drop admin page, but I could not use them. I also wanted to support gravatars, which show an image chosen by the author alongside their comments, and to add a ratings system.

Ratings are a lot of fun, though not really reliable as a gauge of quality. If your article extolling the merits of the Xbox 360 gets linked by a PlayStation fan site, or your article critical of Apple gets linked by an Apple fan site, there is little chance of a fair rating. Some readers also find it difficult to separate what they think about the subject matter from what they think about the quality of reporting. Even so, ratings are always interesting and I’d like to include a list of best-rated posts.

It has taken me some time to find a theme that looked right for my needs, but I have now settled on Atahualpa from BytesForAll. It is a popular theme, so my blog will look similar to many others, but it is flexible and I’ve been able to add the most important features by modifying settings rather than editing the raw PHP, a critical issue for upgradability. I’ve also added rating support with GD Star Rating.

As ever, it is work in progress, and I expect to modify the design and add features as time allows. Although it may not look much improved yet, it is much easier to modify in a maintainable fashion, so expect more changes soon.