<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>etrium(Dan&#039;s stuff)</title>
	<atom:link href="http://www.etrium.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etrium.co.uk</link>
	<description>Nerdtastic</description>
	<lastBuildDate>Sat, 13 Mar 2010 20:08:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>XMLHttpRequest Misuse on Page Load with AJAX</title>
		<link>http://www.etrium.co.uk/2010/03/12/xmlhttprequest-misuse-on-page-load-with-ajax/</link>
		<comments>http://www.etrium.co.uk/2010/03/12/xmlhttprequest-misuse-on-page-load-with-ajax/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 00:34:44 +0000</pubDate>
		<dc:creator>danbrown</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Webdev]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[MiniRant]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[XMLHttpRequest]]></category>

		<guid isPermaLink="false">http://www.etrium.co.uk/?p=124</guid>
		<description><![CDATA[Introduction
XMLHttpRequest is a JavaScript function that allows the core dynamic data part of AJAX (Asynchronous JavaScript And XML) to work. It lets JavaScript running in a web browser call a URL on the same server and receive data back again to process. Either normal HTML, XML or any format such as JSON can be returned [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p>XMLHttpRequest is a JavaScript function that allows the core dynamic data part of AJAX (Asynchronous JavaScript And XML) to work. It lets JavaScript running in a web browser call a URL on the same server and receive data back again to process. Either normal HTML, XML or any format such as JSON can be returned and the JavaScript can do what it likes with it. This lets the page update itself or submit a form without making the whole page refresh which typically gives the user a much better experience. Obvious examples are a news website with up-to-date news &#8216;ticker&#8217;-style headlines or live sports commentary, Viewing more comments in YouTube, Search engine pop-up suggestions as you type, and so on.</p>
<p><span id="more-124"></span></p>
<h2>The Misuse</h2>
<blockquote><p>&#8220;When you have a shiny new hammer, every problem looks like a nail.&#8221;</p></blockquote>
<p>As a way to update a page or get new data according to user actions or a timer this is incredibly powerful. But I see so many sites using it as a way to fill in the initial content <em>during</em> the initial page load. Apart from slowing down the overall page load itself by making additional requests to the server, it gives a jarring wait when it looks like it should have finished but then goes on to display &#8216;Loading&#8230;&#8217; or worse, nothing. I am not writing this to give a flashy solution, it should be obvious for developers. I wrote it to raise awareness that it is a problem.</p>
<p>As an example, and not picking on him in any way, Ben Marsh made a hit website last year that became very popular during this winters snow and I&#8217;m sure will again in the future &#8211; <a href="http://uksnow.benmarsh.co.uk/">http://uksnow.benmarsh.co.uk/</a>. As a social content aggregator and public service it worked fantastically and I spent a large amount of time there myself watching the weather move around the UK. But watch what happens when you load/refresh the page&#8230; The main part loads, the Google Maps interface comes up and the tweet panel sits there empty with a message at the top saying &#8216;Updating tweets&#8217;&#8230; He had to cache the messages on his server to avoid the twitter API locking him out so it is all stored there to use. So why are we waiting? The data can&#8217;t have changed significantly in the few seconds since the page loaded so why isn&#8217;t the list pre-populated as part of the page load itself? It makes the page extremely slow to load, especially when the server load was very high in the worst of the cold spell.</p>
<p>A worst-case example was a mapping component I saw on an internal government department website. In IE8 and Firefox it cached things and worked reasonably but in IE6, which we are forced to use at work, it reloaded every icon and menu item multiple times (over a thousand requests for a single refresh) after the page load. It sometimes took a full minute to bring the map system up fully&#8230; This wasn&#8217;t even dynamic content! The map part worked fine once it was working, it was the map layer menu and fixed icons that it was reloading which would have stayed the same for months at a time. It was live for about a week before they had so many complaints that they had to go back to the old ActiveX version which they still use six months later. They also have a site main menu that loads via AJAX after the page load and a few forms that reload several seconds after the page has loaded, resetting the focus and making me type into nothing until I notice half a blank sentence later.</p>
<h2>Why it happens</h2>
<p>The reason for this, I believe, is a misguided attempt to avoid duplicate code &#8211; One block for the AJAX handler and another almost identical on the page load. As developers it is easy to look for ways to re-use code (or just avoid re-writing it again), put two and two together and decide to use the AJAX version for both purposes. Running on a local unstressed web server it is pretty responsive and people may either not test it remotely or work in a company where the production server is also local. This means they never notice how slow and/or visually odd it is for real world users.</p>
<p>Another reason that this may sadly become more common is Googles recent announcement that they may take page load time into account for rankings. Some web spiders (although not Googles I believe) don&#8217;t do JavaScript and so will see the empty page as the full load time. Misusing XMLHttpRequest this way will let them get a better &#8217;score&#8217; on some phrase if that search engine adopts the time measurement also.</p>
<p>This does cause another  SEO problem with bots that can&#8217;t follow AJAX requests &#8211; If the initial data never gets loaded, it can&#8217;t be indexed. So no free secondary &#8217;splash&#8217; search engine ranking when a phrase matches something in their content. Plenty of non-techy website owners that use cheap outsourcing facilities would put page rank on a specific page/phrase above this other method of getting free incoming traffic as they simply don&#8217;t know about it. The 2nd world ultra-low budget bulk outsourcing firms aren&#8217;t going to care which method they use if they can claim to boost pagerank.</p>
<h2>How to avoid</h2>
<p>Very easily -</p>
<p>Make both your AJAX handler and the main page generating code call a common function which generates the content. Tada! &#8211; code reuse and faster, smooth page loads for users.</p>
<p>You may already have a function for it but it outputs XML or JSON. That&#8217;s usable too &#8211; output it into a JavaScript variable as part of the main page and once the page is loaded call the same JavaScript routine to parse and display it that the  XMLHttpRequest callback uses. It&#8217;s not quite as smooth that way but still vastly preferable to a return trip to the server + processing time.</p>
<p>Your page size will go up. That is saved by not having to do a second server request so it actually ends up about the same bandwidth used apart from in one case &#8211; If your original page can be cached. It&#8217;s up to you if the slight bandwidth saving is worth giving your users/customers a worse experience for. If you have an e-commerce site you should already know how fickle a large percentage of customers can be and a very slow page load can be a good enough reason for them to leave your site and go to the next one the search engine suggests.</p>
<h2>Conclusion</h2>
<p>Test your sites remotely on a stressed server to see it the same way a user does.</p>
<p>There are valid reasons to use XMLHttpRequest this way, mainly if the user expects it not to be instant anyway. Google Maps is a good reason to load content just after the page load as it can&#8217;t tell browser dimensions until then.</p>
<p>Are there any others? Have you noticed this as a problem as well or do you think it isn&#8217;t worth worrying about?</p>
<p>Leave feedback in the comments if you want.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etrium.co.uk/2010/03/12/xmlhttprequest-misuse-on-page-load-with-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#include &#8220;blog&#8221;</title>
		<link>http://www.etrium.co.uk/2010/02/06/begin/</link>
		<comments>http://www.etrium.co.uk/2010/02/06/begin/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 13:57:22 +0000</pubDate>
		<dc:creator>danbrown</dc:creator>
				<category><![CDATA[Misc]]></category>
		<category><![CDATA[about]]></category>

		<guid isPermaLink="false">http://www.etrium.co.uk/?p=1</guid>
		<description><![CDATA[An introduction to the blog and what it may contain]]></description>
			<content:encoded><![CDATA[<p>I thought it was about time I started a real blog and so here we are.</p>
<p>I do write on blogs for two projects I work on, however both are fairly specific so I wanted one I can ramble on about anything I am interested in or up to. There is no specific theme to this other than general geekery. I&#8217;ll list each of my interests below so you have fair warning of what I may post about -</p>
<p><span id="more-1"></span></p>
<h3>Programming</h3>
<p>Nowadays I mostly use PHP for hobbies, but I also like to keep my toe dipped into the C/C++ pond and have VBA inflicted upon me at work sometimes. I like to think I am keeping up with coding standards and methodologies however you wouldn&#8217;t know that from reading my code&#8230;</p>
<p>I run two small open source projects, one active (<a title="Moa" href="http://www.moagallery.net/">Moa</a>, a web-based image gallery) and one currently inactive but still used (<a title="Titan" href="http://titan.sourceforge.net/">Titan</a>, a C++ image loading/saving library). I am working on a third at weekends &#8211; a raid DKP tracking system for World of Warcraft, no link yet. And a fourth hopefully launched before the end of the year for a web-based astronomy observation log.</p>
<p>I have always wanted to write games, though other things always get in the way. So no surprise I have one of those in development as well. Only a simple asteroids clone but with a few extras thrown in for good measure. It has been on hold for over a year now due to concentrating on Moa.</p>
<h3>Digital Electronics</h3>
<p>I mean making devices, not buying them. Modern microcontrollers such as the Microchip PIC and some experience of low-level assembler from my early PC days made this a fairly easy transition from PC programming.</p>
<p>I have two projects so far in this field. First is a camera intervalometer that triggers a camera via infra-red at a set frequency to make time-lapse video (<a title="Time-lapse video on YouTube" href="http://www.youtube.com/watch?v=Ab5Rq_dpZUw">link</a> to my first test). Second is a device I made for my telescope to enable auto-guiding (working) and periodic error correction (semi-working) on my telescope mount with a webcam. I need to rewrite the software for the latter project when I am able to get the scope out again.</p>
<p>I couldn&#8217;t do analogue electronics to save my life.</p>
<h3>Photography</h3>
<p>I got into this as I wanted to do astro-photography. I bought an old film Olympus OM10 SLR camera but ended up using it more for regular pictures than astronomy ones. I upgraded to an Olympus C-5050 Zoom digital compact soon afterwards and now use a Nikon D60 digital SLR. I make no claims to being any good at photography and I have a lot to learn still, but I enjoy it and do get some good pics occasionally. My personal gallery (using Moa) is <a title="My photo gallery" href="http://www.etrium.co.uk/photo/">here</a>.</p>
<h3>Astronomy</h3>
<p>I took a course at the <a title="Open University" href="http://www.open.ac.uk/">Open University</a> a few years back in Planetary Science and bought a cheap 30mm refractor from Cash Convertors as I thought it might help. I enjoyed looking at the night sky and trying to find those faint fuzzy galaxies/nebulae so much a few months later I splashed out and got a 6 inch reflector. A 9am start at work with bad weather and heavy light pollution due to living in an estate play havoc with being able to use it often now though. I should be moving in a couple of months though and a ground floor flat with dark(ish) garden will be high on my list of requirements. I use a webcam to take pictures now, being far more convenient than an SLR. It is low-resolution and grainy, but I get some OK pics considering its those limitations (<a title="my astro pics" href="http://www.harthinian.com/astro/images.html">gallery</a>).</p>
<h3>Gaming</h3>
<p>You think I have time left over to play games as well! Well, OK I do. Mainly World of Warcraft a few nights a week and Battlefield 2 about the same. So much crap is pumped out these days though that I don&#8217;t play many other modern games. When I get time I like to play the old classics that blow a lot of todays games out of the water &#8211; XCOM and Terror From the Deep, Thief, Final Fantasy 7-9, Elite, Civilisation, Wizball, Head Over Heels, Sim City and sometimes even The Sims. Two new games I am looking forward to when they are eventually released are Thief 4 and Half Life 2: Episode 3.</p>
<p>I would also like to get into paper and pen role playing games, however convincing friends that they want to as well is harder than I thought it would be. I&#8217;ve never played D&amp;D but would like to try. I have played both Heroes Unlimited and Call of Cthulhu and would happily play both again regularly. I am still surprised with things like Skype, Social Media and much more Internet-savvy people around that there isn&#8217;t a app to do this and let people find other like-minded players rather than being pre-arranged amongst friends. There is one simple one I found but was very dated and clunky to use. Maybe I should launch a fifth open source project as well&#8230;</p>
<h3>Technology</h3>
<p>I like trying new things, within the range of my wallet at least. And so when possible I try new software and hardware to see how things work. I try not to follow the crowd, not out of stubborness but because someone else will always get one I can have a play with instead. One thing seems to be universal though &#8211; Manufacturers are appear to be very ignorant of what people will actually be doing with their device/software and the usability suffers a lot.</p>
<p>In theory I use Linux as my desktop OS. In reality I spend about half my time in Windows due to Linux just plain not being ready for full-time use yet. More about that to come in a post shortly.</p>
<h3>Fiction (mainly Science Fiction and Horror)</h3>
<p>I like to read hard sci-fi and get both <a title="Analog magazine" href="http://www.analogsf.com/index.html">Analog</a> and <a title="Asimovs magazine" href="http://www.asimovs.com/index.shtml">Asimovs</a> magazine most months. Novels as well of course and I am currently re-reading Red Mars by Kim Stanley Robinson. Most TV and movies are soft-sci-fi though and rightly so or their ratings would plummet. They do tend to end up getting trapped in formulaic ruts or using the sci-fi technology as a replacement for a good plot though. Some of the supposedly geek fan-favourite sci-fi classics I couldn&#8217;t stand though, Enders Game particularly, also Dune and Snow Crash.</p>
<p>Horror I like also, although a good modern horror novel seems hard to find now. Back in school during the 80&#8217;s it was great with James Herbert, Shaun Hutson, Steven King, etc bringing new books out fairly regulary. So I tend to re-read those or go further back in time to the great grand-daddies of them all &#8211; HP Lovecraft and Edgar Allen Poe.</p>
<p>I do read other genres as well. I like the Harry Potter series even though I generally don&#8217;t like fantasy. The Beach, Fight Club, On the Road, Fear and Loathing in Las Vegas, etc are all great books. One plot-type that I especially like, regardless of genre, is the castaway. Not sure why but it seems to be a recurring theme in some of my favourite books/movies.</p>
<h3>Science Fact</h3>
<p>I learn for pleasure. Always have done and so perhaps it isn&#8217;t surprising that I have taken a few courses and try and keep up to date in stuff I want to know more about. So far with the Open University I have done courses in Planetary Science, Oceanography, Geology, Optics and Artificial Intelligence. Not for any reason or qualification, just to know more about the subject.</p>
<p>One thing that I may write about is conspiracy theories. I don&#8217;t believe any of them personally, but I find the mindset behind them bizarre. 9/11, Moan Hoax, Climate Change Denial, New World Order, Reptilians, Area 51, etc. All demonstrably bullshit yet people still actively find excuses and even make stuff up just so they can carry on believing.</p>
<h3>Travel</h3>
<p>Something I wish I had the opportunity to do more often. My last four holidays have been to Thailand and Japan, twice each. All have been with backpacks staying in hostels and guest houses and I wouldn&#8217;t trade them for a hotel/resort holiday for anything. For me the purpose of the holiday is to see other countries/cultures not just get a tan, get drunk and come home with some souvenirs.</p>
<p>I am currently planning and saving  for a 5-6 month trip around the world probably to be taken in the summer of 2011. None of this &#8216;fly around the world stopping in 3-4 countries  and say you have travelled around the world&#8217; crap either.  Over land/sea from the UK through Europe, across Russia, Mongolia and into China, down through southeastern Asia to Australia. Then New Zealand over to South America and up by bus into the US and across to the east coast. It does involve four flights I can&#8217;t really avoid though &#8211; Bali-&gt;Darwin, Sydney-&gt;Christchurch, Auckland-&gt;Santiago and Boston-&gt;Glasgow but I worked out the land-based travel is in-excess of 30000 miles, 10000 more for the flights. I did hope to do it this year but work issues mean it would be better put off for now. Thinking of spending 3 weeks or so InterRailing in Europe during October at the moment for this years holiday.</p>
<h3>About me</h3>
<p>Not a subject I will write about, but for info.</p>
<p>I am 33, male and live near Aldershot in the UK. I work for a geotechnical department of a global company in Woking doing none of the above although occasionally get to do some Visual Basic coding within Microsoft Access.</p>
<p><em>Dan Brown (no, not that one)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.etrium.co.uk/2010/02/06/begin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
