<?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>bybjorn.com &#124; Bjørn Børresen - freelance web developer &#187; Javascript</title>
	<atom:link href="http://www.bybjorn.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bybjorn.com</link>
	<description>bybjorn.com &#62;&#62; Bjørn Børresen - freelance web developer</description>
	<lastBuildDate>Tue, 27 Jul 2010 11:08:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Dynamic loading of Javascript</title>
		<link>http://www.bybjorn.com/56/</link>
		<comments>http://www.bybjorn.com/56/#comments</comments>
		<pubDate>Sat, 07 Oct 2006 10:47:51 +0000</pubDate>
		<dc:creator>Bjørn Børresen</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://bie.no/blog/computers/software-engineering/javascript/2006/10/dynamic-loading-of-javascript/</guid>
		<description><![CDATA[When programming desktop applications I&#8217;ve always been a supporter of lazy loading of objects but I&#8217;ve never given this much thought when creating websites. Until now. What happened you ask? Well, one of my sites got dugg earlier this week. As most of you know, this means a lot of visitors in a short period [...]]]></description>
			<content:encoded><![CDATA[<p>When programming desktop applications I&#8217;ve always been a supporter of lazy loading of objects but I&#8217;ve never given this much thought when creating websites. Until now.
<span id="more-56"></span>
What happened you ask? Well, <a href="http://www.43min.com">one of my sites</a> <a href="http://www.digg.com/videos_comedy/What_if_everyone_were_telling_the_truth">got dugg</a> earlier this week. As most of you know, this means a lot of visitors in a short period of time, often referred to as the <a href="http://en.wikipedia.org/wiki/Slashdot_effect">Slashdot/Digg Effect</a>. I&#8217;m planning on blogging on this experience in a bit, so I&#8217;ll skip that part for now (come back in a couple of days if you&#8217;re interested). So, let&#8217;s move on to &#8230;</p>

<h2>Why is this a good idea for (some) websites</h2>

<p>I&#8217;ll use <a href="http://www.43min.com/archive/view/en/48-Suits-telling-the-truth-....html" title="What if everyone were telling the truth?">the page that got dugg</a> as an example. It&#8217;s basically a page with a video from Google Video with some controls on the right side which can be used for adding comments or sending the video to a friend.</p>

<p>A couple of facts:
- These controls are <em>AJAX based</em>, and I use the infamous <a href="http://prototype.conio.net/">prototype.js</a> for this.
- prototype.js is 47k
- About 0,03% of the visitors write comments/send e-mail and prototype.js is only used when this is done
- When I was dugg, I used 1,7GB in bandwidth <em>only for prototype.js</em>!</p>

<p><em>Starting to get the picture?</em></p>

<p>If some javascripts are only used by a small percentage of your visitors &#8211; <em>why load them each time</em>? It will only cost you bandwidth and your visitors download time. <strong>It took me digg to drain 1.7GB of my bandwidth unnecessary for me to get this</strong> <img src='http://www.bybjorn.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  &#8230; Lazy loading is the key. Or dynamic loading of .js files if you will.</p>

<p>So, I started doing some research, and asked around in #javascript on ef-net. One user there, km0tion, linked me to <a href="http://xkr.us/code/javascript/include.js">this script</a> which was exactly what I needed. Here&#8217;s the code:</p>

<p>/** include &#8211; including .js files from JS &#8211; bfults@gmail.com &#8211; 2005-02-09    **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
var hIncludes = null;
function include(sURI)
{
  if (document.getElementsByTagName)
  {
    if (!hIncludes)
    {
      hIncludes = {};
      var cScripts = document.getElementsByTagName(&#8220;script&#8221;);
      for (var i=0,len=cScripts.length; i &lt; len; i++)
        if (cScripts[i].src) hIncludes[cScripts[i].src] = true;
    }
    if (!hIncludes[sURI])
    {
      var oNew = document.createElement(&#8220;script&#8221;);
      oNew.type = &#8220;text/javascript&#8221;;
      oNew.src = sURI;
      hIncludes[sURI]=true;
      document.getElementsByTagName(&#8220;head&#8221;)[0].appendChild(oNew);
    }
  }
}</p>

<p>So the clue would be to only include <a href="http://xkr.us/code/javascript/include.js">include.js</a> when loading the page, and then using it&#8217;s <em>include()</em> function to retrieve prototype.js and the other files. This is only done the first time a user uses the controls on your page that needs the AJAX libraries. Of course, it would be a good idea to show that familiar <em>ajax loading image</em> when doing this <img src='http://www.bybjorn.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<p>Can&#8217;t wait to implement this on <a href="http://www.43min.com" title="Funny movies, baby!">43min.com</a>.</p>

<p>Also, I plan on analyzing the digg effect in a post the next days, and also letting you know how <a href="http://www.codeigniter.com">Codeigniter</a> handled the traffic (43min is built on CI) &#8211; so if this is stuff you find interesting you might want to <a href="http://feeds.feedburner.com/bjornblog">subscribe to my feed</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bybjorn.com/56/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Google Web Toolkit</title>
		<link>http://www.bybjorn.com/36/</link>
		<comments>http://www.bybjorn.com/36/#comments</comments>
		<pubDate>Sat, 27 May 2006 09:28:59 +0000</pubDate>
		<dc:creator>Bjørn Børresen</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://bie.no/blog/computers/software-engineering/ajax/2006/05/google-web-toolkit/</guid>
		<description><![CDATA[Just a short note, i found this today &#8211; Google Web Toolkit. It looks very promising and I&#8217;m just about to start experimenting with it (can&#8217;t wait!). It&#8217;s a framework for creating AJAX applications with the usual gmail look, but the fresh approach is that you write the application in Java &#8211; and then you [...]]]></description>
			<content:encoded><![CDATA[<p>Just a short note, i found this today &#8211; <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a>. It looks very promising and I&#8217;m just about to start experimenting with it (can&#8217;t wait!). It&#8217;s a framework for creating AJAX applications with the usual gmail look, but the fresh approach is that you write the application in Java &#8211; and then you compile to to Javascript/HTML when you&#8217;re ready to ship.</p>

<p>I&#8217;m don&#8217;t how well this development model works with dynamic data etc. but I&#8217;m sure they have a clever way to do that too. Will report more later when I&#8217;ve tested it <img src='http://www.bybjorn.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bybjorn.com/36/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get the AJAX In Place Editor to use ISO-8859-1</title>
		<link>http://www.bybjorn.com/20/</link>
		<comments>http://www.bybjorn.com/20/#comments</comments>
		<pubDate>Thu, 09 Feb 2006 21:05:00 +0000</pubDate>
		<dc:creator>Bjørn Børresen</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://bie.no/blog/metabjorn/2006/02/how-to-get-the-ajax-in-place-editor-to-use-iso-8859-1/</guid>
		<description><![CDATA[When implementing script.aculo.us&#8217; AJAX In Place Editor for a project I&#8217;m currently working on, I ran into some character encoding problems. My PHP framework uses ISO-8859-1, while the ajax script was submitting UTF-8 to my server. Reading the wiki documentation, I discovered that this was a &#8216;known feature&#8217;: The form data is sent encoded in [...]]]></description>
			<content:encoded><![CDATA[<p>When implementing <a href="http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor">script.aculo.us&#8217; AJAX In Place Editor</a> for a project I&#8217;m currently working on, I ran into some character encoding problems. My PHP framework uses ISO-8859-1, while the ajax script was submitting UTF-8 to my server. Reading the <a href="http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor">wiki</a> documentation, I discovered that this was a &#8216;known feature&#8217;:</p>

<blockquote>The form data is sent encoded in <span class="caps">UTF</span>-8 regardless of the page encoding.</blockquote>

<p>I was recommended to use iconv to convert back to ISO-8859-1 on the server. Unfortunately this was not an option for me, as it wasn&#8217;t available on the production server. Of course, there is PHP&#8217;s <a href="http://no2.php.net/utf8_decode">utf8_decode()</a>, but anyone who has used it will tell you it is totally unreliable.</p>

<p>So, here&#8217;s how to get it to use the encoding of your page (e.g. ISO-8859-1) instead of UTF-8. This is based on the info I found in <a href="http://dev.rubyonrails.org/ticket/2151">this bug report</a>.</p>

<ul>
    <li>Open prototype.js and replace all calls to <em>encodeURIComponent()</em> with <em>escape()</em>. There should be three instances.</li>
    <li>On the server side, make sure you send all output wrapped with <em>htmlentities()</em>, or else you may experience that the editor &#8216;hangs&#8217; when updating.</li>
</ul>

<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bybjorn.com/20/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging JavaScript with MS Visual Studio</title>
		<link>http://www.bybjorn.com/19/</link>
		<comments>http://www.bybjorn.com/19/#comments</comments>
		<pubDate>Thu, 02 Feb 2006 18:02:09 +0000</pubDate>
		<dc:creator>Bjørn Børresen</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://bie.no/blog/metabjorn/2006/02/debugging-javascript-with-ms-visual-studio/</guid>
		<description><![CDATA[There&#8217;s an ancient fable that tells of a frog that falls into a pail of milk. Unable to scramble out, the creature trashes around, seemingly drowning. Eventually however, his frantic struggles turn the milk into butter &#8211; and he hops away. Until now, that fable has been a good metaphor of my struggle with the [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s an ancient fable that tells of a frog that falls into a pail of milk. Unable to scramble out, the creature trashes around, seemingly drowning. Eventually however, his frantic struggles turn the milk into butter &#8211; and he hops away.</p>

<p>Until now, that fable has been a good metaphor of my struggle with the seven headed beast called JavaScript. I&#8217;ve written my lines of code, gotten inane script errors from IE, tried, failed and tried again. Also known, and forever hated, as <a title="trial and error programming (new window)" target="_blank" href="http://www.c2.com/cgi/wiki?TrialAndErrorProgramming">trial and error programming</a>.</p>

<p>Of course, jolly, happy and cheerful memories from BW2 (before <a title="Web Two Point Schmoe" href="http://jroller.com/page/fate?entry=web_twopointschmoe">Web 2.0</a>) &#8211; when I coded Java all day and all night, with the <a target="_blank" title="Teh best Java IDE, sir!" href="http://www.intellij.com">best tools of the trade</a> &#8211; didn&#8217;t help much either.</p>

<p>So, I felt like the frog. But that was until I discovered that I could debug javascript with Visual Studio. Yes, that&#8217;s right &#8211; actual debugging in javascript.</p>

<p>I&#8217;m not saying this is news, I&#8217;m just saying it&#8217;s <em>news to me</em> (and probably to a couple of others as well &#8211; those weird looking geeks in the corner, there. See them?). And, yes, I am aware of <a title="Mozilla Javascript Debugger" href="http://www.hacksrus.com/~ginda/venkman/">Venkman</a>.</p>

<p>If you&#8217;re not a .net developer, it isn&#8217;t in-your-face obvious how you do this, so often you rely on someone just showing it to you. I&#8217;ve done some screenshots for you guys and gals.</p>

<h3>How to do it!</h3>

<p>Just visit the webpage you want to debug with IE. Then fire up Visual Studio, and select Tools -> Attach to Process&#8230;</p>

<p><img title="Attach to process" alt="Attach to process" src="http://bie.no/images/screenshots/js_debugging_with_visual_studio/attach_to_process.png" />
Then you find the iexplore.exe instance you want. Click &#8220;Attach&#8221;.</p>

<p><img title="Attach to process" alt="Attach to process" src="http://bie.no/images/screenshots/js_debugging_with_visual_studio/attach_to_process_dialog.png" />
And voilá! You&#8217;re in a full-featured debugger; a script explorer, code-view where you can set breakpoints etc. and a panel where you can add watches and view values of locals.</p>

<p><a title="larger version" target="_blank" href="http://bie.no/images/screenshots/js_debugging_with_visual_studio/visual_studio_javascript_de.png"><img title="Click for larger version" alt="Click for larger version" src="http://bie.no/images/screenshots/js_debugging_with_visual_studio/visual_studio_thumb.png" /></a>
This is brilliant. Now this JavaScript programming should feel less like thrashing in a pail of milk, and more like enjoying a cup of hot chocolate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bybjorn.com/19/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>1 Way to Impress Your Friends</title>
		<link>http://www.bybjorn.com/17/</link>
		<comments>http://www.bybjorn.com/17/#comments</comments>
		<pubDate>Sun, 15 Jan 2006 16:17:32 +0000</pubDate>
		<dc:creator>Bjørn Børresen</dc:creator>
				<category><![CDATA[marketing]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[linkbait]]></category>

		<guid isPermaLink="false">http://bie.no/blog/metabjorn/2006/01/1-way-to-impress-your-friends/</guid>
		<description><![CDATA[Or, 24 ways that is. If you&#8217;re were sleeping through december month, or maybe too busy handling your mother-in-law, you might have missed 24ways, the ajax/web2.0 advent calendar. The idea is simple; every day they would release a new ajax/web related article. The articles are written by different authors, who are probably considered experts in [...]]]></description>
			<content:encoded><![CDATA[<p>Or, <a href="http://www.24ways.org">24 ways</a> that is. If you&#8217;re were sleeping through december month, or maybe too busy handling your mother-in-law, you might have missed <a href="http://www.24ways.org">24ways</a>, the ajax/web2.0 advent calendar. The idea is simple; every day they would release a new ajax/web related article. The articles are written by different authors, who are probably considered experts in their field.</p>

<p>It recently struck me how ingenious this is from a marketing point of view. Releasing quality content like this, on a single site and on an pre-known schedule (in this case every day) &#8211; you&#8217;re bound to get <a href="http://www.google.no/search?q=site%3Adigg.com+24ways&#038;start=0&#038;ie=utf-8&#038;oe=utf-8&#038;client=firefox-a&#038;rls=org.mozilla:en-US:official">dugg</a> a lot. People also seem find it <a href="http://del.icio.us/search/?all=24ways">delicious</a>, and it&#8217;s probably just a coincidence that this wasn&#8217;t &#8220;<a title="Slashdot" href="http://www.slashdot.org">news for nerds, stuff that matters</a>&#8220;.</p>

<p>This will without doubt create a sort of a synergy effect where all the authors get extra traffic (they are all linked to from the article listing in additon to the article). When bloggers get together and release something like this, their chances of getting large amounts of traffic multiplies. Sure, the main site gets hit the most (in this case 24ways.org) &#8211; but I suspect the individual authors also got their share (looking at the <a href="http://www.alexa.com/data/details/traffic_details?&#038;range=2y&#038;size=medium&#038;y=r&#038;url=www.snook.ca/jonathan/#top">alexa traffic rankings</a> for a couple of them it seems they had quite an increase in december/january, but that might be coincidental.</p>

<p>Anyway, why didn&#8217;t anyone think of this before? (allright, I&#8217;m sure someone did and I just failed to do some research, but still &#8211; it seems like a good idea to do this for something else than ajax).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bybjorn.com/17/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
