<?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>Software and Opinions &#187; javascript</title>
	<atom:link href="http://ianloic.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://ianloic.com</link>
	<description>from Ian McKellar</description>
	<lastBuildDate>Thu, 19 Nov 2009 22:05:43 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Not solving the wrong problem</title>
		<link>http://ianloic.com/2009/10/08/not-solving-the-wrong-problem/</link>
		<comments>http://ianloic.com/2009/10/08/not-solving-the-wrong-problem/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 23:40:29 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=147</guid>
		<description><![CDATA[I like a great deal of what Google does for the open web. They sponsor standards work, they are working on an open source browser, they are building documentation on the state of the web for web developers. It&#8217;s all really great. Today they posted what they called A Proposal For Making AJAX Crawlable. It [...]]]></description>
			<content:encoded><![CDATA[<p>I like a great deal of what Google does for the open web. They <a href="http://en.wikipedia.org/wiki/Ian_Hickson">sponsor standards work</a>, they are working on an <a href="http://code.google.com/chromium/">open source browser</a>, they are <a href="http://code.google.com/doctype/">building documentation</a> on the state of the web for web developers. It&#8217;s all really great. Today they posted what they called <a href="http://googlewebmastercentral.blogspot.com/2009/10/proposal-for-making-ajax-crawlable.html">A Proposal For Making AJAX Crawlable</a>. It seems like a great idea. More and more of the web isn&#8217;t reached by users clicking on a conventional &lt;a href=&#8221;http://&#8230; link but by executing JavaScript that dynamically loads content off of the server. It&#8217;s somewhere between really hard and impossible for web crawlers to fully and correctly index sites that work that way without the sites&#8217; developers taking crawlers into account.</p>
<p>Google&#8217;s proposal is to define a convention for URLs that contain state information in the anchor and to define a convention for retrieving the canonical, indexable contents of the an URL with such an anchor tag. First let me dismiss the suggestion that you make a headless browser available over HTTP to render your AJAX pages to HTML out of hand. If it&#8217;s so easy for HtmlUnit to render your AJAX to HTML, surely Google can do it. And basically offering HtmlUnit as a web service on your server doesn&#8217;t sound that secure or scalable to me.</p>
<p>The bigger question is that if your solution requires the server to be able to serve the correct HTML for any state, would you come up with the same solution as Google? There is a simple, straight-forward solution that works today and is used on sites all over the internet. If the content you serve includes the static, non AJAX URLs in anchor HREFs but uses JS click handlers to do AJAX loads then crawlers can scrape all of your pages, users of modern browsers get the full shiny experience and users on old mobile browsers that don&#8217;t support JS get to work for free!</p>
<p>To do this you can either make your AJAX templates include onclick handlers or you can write a simple piece of JS to do the right thing when any link is clicked on. A contrived example using jQuery might look like:</p>
<pre class="prettyprint">      $(function(event) {
        $('body').click(function(event) {
          var href = $(event.target).attr('href');
          // don't try to AJAX absolute URLs
          if (href.match('https?://')) return;
          // don't let the normal browser navigation operate
          event.preventDefault()
          // based on event.target.href, decide what AJAX URL to load.
          $('#ajaxframe').load('/load-fragment', {path: href});
          // update the URL bar
          document.location.hash=href;
        });
      });</pre>
<p>This will intercept clicks on relative anchor tags and let your page JS do its AJAX magic. It doesn&#8217;t require special conventions. If you build your site this way you&#8217;ll probably find that the state that is in your URL fragments is a the relative URL for the page on your site. So http://www.example.com/random/page and http://www.example.com/#/random/page have the same meaning. That turns out to be a pretty good convention. After all, aren&#8217;t our URLs <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">supposed to</a> refer to resources anyway?</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2009/10/08/not-solving-the-wrong-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Months of ActionScript</title>
		<link>http://ianloic.com/2009/02/27/three-months-of-actionscript/</link>
		<comments>http://ianloic.com/2009/02/27/three-months-of-actionscript/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:45:47 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[ecmascript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=106</guid>
		<description><![CDATA[I&#8217;ve been working largely in ActionScript 3 for the past three months. After spending four years working primarily in JavaScript I didn&#8217;t expect to encounter too many problems with her cousin. That expectation was pretty well borne out.
I was particularly excited at the chance to play with ActionScript&#8217;s optional strict typing since that has been [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working largely in <a href="http://en.wikipedia.org/wiki/ActionScript">ActionScript 3</a> for the past three months. After spending four years working primarily in <a href="http://en.wikipedia.org/wiki/JavaScript">JavaScript</a> I didn&#8217;t expect to encounter too many problems with her cousin. That expectation was pretty well borne out.</p>
<p>I was particularly excited at the chance to play with ActionScript&#8217;s optional strict typing since that has been under consideration for future versions of JavaScript / <a href="http://en.wikipedia.org/wiki/ECMAScript">ECMAScript</a>. AS3&#8217;s strict typing hasn&#8217;t felt optional to me because I&#8217;ve been largely using the <a href="http://en.wikipedia.org/wiki/Adobe_Flex_Builder">Flex Builder IDE</a> and it excitedly warns me every time I fail to specify a type on a variable or function signature, so I put them everywhere. Instead of implementing encapsulation using conventions like I do in JS I use AS3&#8217;s Interfaces. This felt good at first but I quickly realized that I couldn&#8217;t do the kinds of tricks that I&#8217;d become accustomed to in JS. I can&#8217;t create a typed object in a function and return it without defining a class for it in its own file. This has made the higher level structure of my software far closer to Java than to JavaScript.</p>
<p>On the other hand, inside my functions I&#8217;m pretty much writing JavaScript. All of the standard JS built-in objects (Object, Array, Math, etc) behave like modern JS implementations. I use anonymous functions to manipulate and filter arrays. I use Objects and Arrays as my primary data structures.</p>
<p>At this point I&#8217;m pretty used to AS3. I know how to design my code and I can be pretty productive, not needing to rewrite everything too many times. I&#8217;d like to see Adobe mix the Java-style classes and interfaces up with the JavaScript habit of declaring anonymous functions and objects as you go. I&#8217;d be thrilled if I could write something like:<br />
<code><br />
var x : IMyInterface = new IMyInterface {<br />
method: function() : void { ... },<br />
field: 42<br />
};<br />
</code></p>
<p>I see that they&#8217;re extending the language to support <a href="http://thebackbutton.com/blog/65/new-vector-actionscript-3s-typed-array/">limited generics support</a> so hopefully that won&#8217;t be the end of it. I&#8217;m looking forward to experimenting more on the platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2009/02/27/three-months-of-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Translation</title>
		<link>http://ianloic.com/2008/04/22/twitter-translation/</link>
		<comments>http://ianloic.com/2008/04/22/twitter-translation/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 05:37:48 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[translation]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=52</guid>
		<description><![CDATA[My friend Britt mentioned today that he was about to launch twitter.jp. How exciting! But I don&#8217;t understand Japanese. If only I could easily translate all those tweets in languages I don&#8217;t understand.
I played around with Google&#8217;s new AJAX Translation API before and I wondered how hard it would be to use that from a [...]]]></description>
			<content:encoded><![CDATA[<p>My friend <a href="http://twitter.com/bs">Britt</a> mentioned today that he was about to launch <a href="http://twitter.jp/">twitter.jp</a>. How exciting! But I don&#8217;t understand Japanese. If only I could easily translate all those tweets in languages I don&#8217;t understand.</p>
<p>I played around with Google&#8217;s new <a href="http://code.google.com/apis/ajaxlanguage/">AJAX Translation API</a> <a href="http://ianloic.com/2008/03/20/google-ajax-apis-outside-the-browser/">before</a> and I wondered how hard it would be to use that from a <a href="http://www.greasespot.net/">GreaseMonkey</a> script. The answer: hard. I&#8217;m not sure what the exact problem was but every way I tried to include Google&#8217;s APIs into the pages I was manipulating, including creating my own <code>iframe</code> and using <code>document.write</code> failed. In the end I used a static proxy html file (hosted in one of my Amazon S3 buckets for cheap efficiency) with some sneaky cross-site communication (the request goes over in location.hash, the response comes back in window.name).</p>
<p>My script is now up on userscripts.org: <a href="http://userscripts.org/scripts/show/25508">twitlator.user.js</a></p>
<p>To use it simply go to a page listing a bunch of tweets, like the <a href="http://twitter.com/public_timeline">public timeline</a> and find a tweet in a language you don&#8217;t under stand. For example:</p>
<p><img class="alignnone size-full wp-image-53" title="A tweet" src="http://ianloic.com/wp-content/uploads/2008/04/twitlator-1.png" alt="" /></p>
<p>Click the <strong>translate!</strong> link and several moments later you&#8217;ve got:</p>
<p><img class="alignnone size-full wp-image-54" title="A translated tweet" src="http://ianloic.com/wp-content/uploads/2008/04/twitlator-2.png" alt="" /></p>
<p>Yep. People aren&#8217;t posting anything interesting in Japanese either.</p>
<p>I&#8217;m pretty sure my script will only work on <a href="http://www.mozilla.com/en-US/firefox/all-beta.html">Firefox 3</a>. I&#8217;m using <code>getElementsByClassName</code> which I think wasn&#8217;t introduced until Firefox 3. Why aren&#8217;t you running it already?</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2008/04/22/twitter-translation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google AJAX APIs outside the browser</title>
		<link>http://ianloic.com/2008/03/20/google-ajax-apis-outside-the-browser/</link>
		<comments>http://ianloic.com/2008/03/20/google-ajax-apis-outside-the-browser/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 21:35:28 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[rhino]]></category>

		<guid isPermaLink="false">http://ianloic.com/?p=48</guid>
		<description><![CDATA[Google just announced their new Language API this morning. Unfortunately their API is another one of their AJAX APIs &#8211; that are designed to be used from JavaScript in web pages. These APIs are pretty cool for building client-side web applications &#8211; I used their AJAX Feeds API in my home page &#8211; but I [...]]]></description>
			<content:encoded><![CDATA[<p>Google just <a href="http://googleblog.blogspot.com/2008/03/new-google-ajax-language-api-tools-for.html">announced</a> their new <a href="http://code.google.com/apis/ajaxlanguage/">Language API</a> this morning. Unfortunately their API is another one of their <a href="http://code.google.com/apis/ajax/">AJAX APIs</a> &#8211; that are designed to be used from JavaScript in web pages. These APIs are pretty cool for building client-side web applications &#8211; I used their <a href="http://code.google.com/apis/ajaxfeeds/">AJAX Feeds API</a> in my <a href="http://ian.mckellar.org/">home page</a> &#8211; but I had some ideas for server software that could use a translation API.</p>
<p>I remembered <a href="http://ejohn.org/blog/bringing-the-browser-to-the-server/">John Resig&#8217;s hack</a> from a few months back, getting enough of the DOM in <a href="http://developer.mozilla.org/en/docs/Rhino">Rhino</a> to run some of the jQuery unit tests. I pulled that down, wrote the bits of DOM that were missing and now I&#8217;ve got a Java and JavaScript environment for accessing Google&#8217;s AJAX APIs. Apart creating stubs for some methods that are called the main functionality I had to implement was turning Google&#8217;s APIs&#8217; asynchronous script loading into the Rhino shell&#8217;s <code class="prettyprint">load(url)</code> calls. They use <code class="prettyprint">&lt;script src="...</code> and <code class="prettyprint">document.createElement("script")</code>, but both are pretty easy to catch. The upshot of this is that everything is synchronous. This subtly changes a lot of the interface. For example, my Language API example looks like this:</p>
<pre class="prettyprint">load('ajax-environment.js');
load('http://www.google.com/jsapi');
google.load('language', '1');
google.language.translate("Hello world", "en", "es",
  function(result) {
    print(result.translation);
  });</pre>
<p>it of course prints: <code>Hola mundo</code>.</p>
<p>I&#8217;ve put the <a href="http://github.com/ianloic/google-ajax-server">source up on github</a>. Have a play, tell me what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2008/03/20/google-ajax-apis-outside-the-browser/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Songbird 0.3</title>
		<link>http://ianloic.com/2007/11/03/songbird_0_3/</link>
		<comments>http://ianloic.com/2007/11/03/songbird_0_3/#comments</comments>
		<pubDate>Wed, 30 Nov -0001 00:00:00 +0000</pubDate>
		<dc:creator>Ian McKellar</dc:creator>
				<category><![CDATA[Default]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[songbird]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Last week <a href="http://www.songbirdnest.com/">we</a> release <a href="http://www.songbirdnest.com/Songbird_0_3_Is_Launched">Songbird 0.3</a>. It's the release I've been working on since I joined the Pioneers of the Inevitable in January. There are a whole lot of improvements in there to various parts of the application - the database engine was rewritten to be faster and more extensible, we added tabs to the browser, etc - but that's not what's really cool. What's really cool is the new Web API we've developed.]]></description>
			<content:encoded><![CDATA[<p>Last week <a href="http://www.songbirdnest.com/">we</a> release <a href="http://www.songbirdnest.com/Songbird_0_3_Is_Launched">Songbird 0.3</a>. It&#8217;s the release I&#8217;ve been working on since I joined the Pioneers of the Inevitable in January. There are a whole lot of improvements in there to various parts of the application &#8211; the database engine was rewritten to be faster and more extensible, we added tabs to the browser, etc &#8211; but that&#8217;s not what&#8217;s really cool. What&#8217;s really cool is the new Web API we&#8217;ve developed.</p>
<p>Web pages being displayed in Songbird can (with the user&#8217;s permission) interact with pretty much the whole music player. We&#8217;re exposing both basic playback controls (what&#8217;s the current track, play, pause, next, etc) and access to the music library (see what&#8217;s in the library, add to it, etc). This means any music web site can offer a really rich integrated experience. Sites like last.fm or Pandora could offer recommendations without requiring you to download a plugin or desktop application, music stores like Emusic or Amazon.com wouldn&#8217;t need to provide a separate desktop applications and could offer the kind of seamless player / web-service integration that only Apple is providing at the moment, and there are a million other possibilities that we haven&#8217;t even thought of yet. Right now you can see this at work on <a href="http://hypem.com/">The Hype Machine</a>.</p>
<p><a href="http://skrul.com/">Steve</a> and I have been hacking on <a href="http://addons.songbirdnest.com/extensions/detail/79">Greasemonkey</a>, getting it integrated with the bird and writing userscripts that add new functionality to web sites that don&#8217;t yet know about Songbird. My most complete hack is one that adds album previews (courtesy of Amazon.com&#8217;s music store) to album reviews on <a href="http://www.metacritic.com/">Metacritic</a> and <a href="http://www.pitchforkmedia.com/">Pitchfork</a>. It&#8217;s useful and its fun!</p>
<p>PS: yes, it supports your bloody iPod&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://ianloic.com/2007/11/03/songbird_0_3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
