<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Straight Ornamental: Category Javascript</title>
    <link>http://grahamstratton.org/blog/public/articles/category/javascript</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ramblings from a rambler</description>
    <item>
      <title>File Uploads</title>
      <description>&lt;p&gt;Until recently I hadn&amp;#8217;t realised that there is an issue with file uploads, but now I have and there definitely is.&lt;/p&gt;


	&lt;p&gt;The problem is that it&amp;#8217;s very difficult to give the user information about the progress of their upload, and if she is uploading a large number of large files this might be an issue.&lt;/p&gt;


	&lt;p&gt;Photobox have gotten round the problem by writing a java applet which is responsible for uploads, but this is overkill for many projects. (But it does also allow users to efficiently upload large numbers of images).  Facebook also have a java uploader for bulk uploads.  Single file uploads use the iframe trick (more on this later) to display a static message whilst the file is uploading.&lt;/p&gt;


	&lt;p&gt;Client-side javascript can&amp;#8217;t control file uploads, since files are OS-level objects and JavaScript shouldn&amp;#8217;t be allowed anywhere near them.  Any information about the progress of an upload must come from the server.  There are a couple of commercial projects which offer software to solve this problem.  Both are Perl scripts.  There are no &lt;span class="caps"&gt;PHP&lt;/span&gt; solutions since &lt;span class="caps"&gt;PHP&lt;/span&gt; does not provide any way to monitor the progress on an upload.&lt;/p&gt;


	&lt;p&gt;It should really be the job of the browser to keep the user informed about the status of uploads, but no browsers seem to do so.&lt;/p&gt;


	&lt;h4&gt;Problems on Both Sides&lt;/h4&gt;


	&lt;p&gt;So we need to implement something on the client side to display status information, and something on the server side to monitor the status of the upload.  Finally we need to get them to talk to each other.  Strangely enough, this bit is probably the easiest bit, thanks to &lt;span class="caps"&gt;AJAX&lt;/span&gt; libraries.&lt;/p&gt;


	&lt;h4&gt;Client side&lt;/h4&gt;


	&lt;p&gt;The problem on the client side is that when a form is submitted, the frame from which it is submitted blocks until the request is completed, so there is no way that it can display status information.  A common trick here is to use a hidden iframe for the upload fields.  There are also slightly more complex examples using &lt;a href="http://development.finetooth.com/?p=11"&gt;multiple iframes&lt;/a&gt;.  (An iframe, by the way, is an inline frame, such as is often used to produce a scrollable box within a page.)&lt;/p&gt;


	&lt;h4&gt;Server side&lt;/h4&gt;


	&lt;p&gt;Here things are even more tricky, as we need to measure how much of a file we have received, and then provide a function that the client can call to return this information.  This is very complex, but not as restrictive as I may have once claimed.&lt;/p&gt;</description>
      <pubDate>Fri, 13 Oct 2006 09:23:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a6c7700b-ea60-4745-9f7b-0ec30a1e178c</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2006/10/13/file-uploads</link>
      <category>Python</category>
      <category>Javascript</category>
    </item>
    <item>
      <title>Javascript libraries</title>
      <description>&lt;p&gt;Having decided that javascript is now mature enough to be worth having a look at, I needed to choose a nice javascript library.  I liked the &lt;a href="http://www.mochikit.com/"&gt;Mochikit&lt;/a&gt; screencast, but I thought I ought to know what else is out there.&lt;/p&gt;


	&lt;p&gt;I came across this rather good &lt;a href="http://www.sitepoint.com/article/javascript-library"&gt;comparison of javascript libraries&lt;/a&gt;.
After reading it I decided that sticking with Mochikit for a while was the way to go.  I feel much better about that now that I have an idea of what I am missing elsewhere.&lt;/p&gt;


	&lt;p&gt;Bob Ippolito has ported many things such as effects from Scriptaculous to Mochikit, leaving the APIs unchanged, which means that switching to Scriptaculous at a later date might not be too hard anyway.  But whilst experimenting, that interactive interpreter looks invaluable.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;ve just viewed the Mochikit screencast again.  It&amp;#8217;s even better than I remembered it being!  If you haven&amp;#8217;t seen it you really ought to!&lt;/p&gt;</description>
      <pubDate>Fri, 06 Oct 2006 11:22:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:135d1541-d69f-4083-8cba-404a36c27761</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2006/10/06/javascript-libraries</link>
      <category>Javascript</category>
    </item>
  </channel>
</rss>
