<?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>bunnyhero dev &#187; HTML5</title>
	<atom:link href="http://www.bunnyhero.org/tag/html5/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bunnyhero.org</link>
	<description>Notes on iPhone, Flash and Web development</description>
	<lastBuildDate>Mon, 07 Nov 2011 21:49:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>iPhone offline web applications: tips and gotchas</title>
		<link>http://www.bunnyhero.org/2010/01/24/iphone-offline-web-applications-tips-and-gotchas/</link>
		<comments>http://www.bunnyhero.org/2010/01/24/iphone-offline-web-applications-tips-and-gotchas/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 01:13:29 +0000</pubDate>
		<dc:creator>bunnyhero</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[application cache]]></category>
		<category><![CDATA[gotchas]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.bunnyhero.org/?p=283</guid>
		<description><![CDATA[I spent this evening updating my &#8220;iPhone VR&#8221; Javascript/CSS demo to work with iPhone OS 3.0 (it had stopped working 100% correctly since the OS update). I also decided to spend some time making it work as an offline-capable web application. The basic process of making your web app cacheable offline is, in theory, fairly [...]]]></description>
			<content:encoded><![CDATA[<p>I spent this evening updating my <a href="http://www.bunnyhero.org/2008/10/13/iphone-vr-viewing-3d-panoramas-in-safari-using-javascript-and-webkit-transform/">&#8220;iPhone VR&#8221; Javascript/CSS demo</a> to work with iPhone OS 3.0 (it had stopped working 100% correctly since the OS update). I also decided to spend some time making it work as an <strong>offline-capable web application</strong>.</p>
<p>The basic process of making your web app cacheable offline is, in theory, fairly straightforward, and generally <a href = "http://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/OfflineApplicationCache.html" >well-documented at Apple&#8217;s website</a>. I ran into some interesting headaches though.</p>
<h3>Gotchas:</h3>
<ul>
<li>First thing to note is that your <strong>web server must serve your cache manifest file with a MIME type of <code>text/cache-manifest</code></strong>. This may mean editing <code>mime.types</code> to add a line that looks like this:

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">text/cache-manifest   manifest</pre></div></div>

<p>or perhaps a line in <code>httpd.conf</code> that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AddType</span> text/cache-manifest  .manifest</pre></div></div>

</li>
<li>The next thing that had me stumped for a while: while your web server may know how to take the URL <code>http://example.com/<strong>webapp/</strong></code> and automatically and invisibly serve up the file <code>http://example.com/<strong>webapp/index.html</strong></code>, <strong>your offline web app knows nothing of this mapping of <code>webapp/</code> to <code>webapp/index.html</code></strong>. If the URL bar reads <code>http://example.com/webapp/</code> and you save it locally using a home screen bookmark, <strong>it will fail to launch correctly if the device is offline, even if <code>index.html</code> file has been cached</strong>. The device simply does not know to look for <code>webapp/index.html</code> instead of <code>webapp/</code>. Thus, you must ensure that the URL bar reads <code>webapp/index.html</code> before the user makes a home screen bookmark.</li>
<li>At first, I thought I would enforce the above with a tiny bit of JavaScript that simply reads <code>window.location</code> and redirects to <code>window.location + "index.html"</code> if the URL ends in a slash. This worked while online, but it broke my app when offline, even when the redirection was not taken. Why? It seems that <strong>any reference to <code>window.location</code> in your script is treated as network access. Since the device is offline, it generates an error alert.</strong>
<p>Instead, I made my app live at <code>webapp/main.html</code>, and created a small <code>webapp/index.html</code> file that simply redirects to <code>main.html</code>. (I could have used a server redirect inside of an <code>.htaccess</code> file instead, but I chose not to, for no particular reason.)</li>
</ul>
<h3>Tips:</h3>
<ul>
<li>You can specify a <strong>custom icon for the home screen bookmark</strong> using a <code>&lt;link&gt;</code> element, like so:

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;apple-touch-icon&quot; href=&quot;custom_icon.png&quot; /&gt;</pre></div></div>

<p><strong>If you don&#8217;t want iPhone to automatically apply the &#8220;shine&#8221; effect on your icon,</strong> use the following instead:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;apple-touch-icon-precomposed&quot; href=&quot;custom_icon.png&quot; /&gt;</pre></div></div>

</li>
<li>Since iPhone OS 3.0, <strong>offline web apps can have custom splash screens</strong>, just a like a native app! Simply add a <code>link</code> element to your web page:

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;apple-touch-startup-image&quot; href=&quot;/splash.png&quot; /&gt;</pre></div></div>

</li>
</ul>
<p>If you want to see the results of all this, go to <a href="http://bunnyherolabs.com/iphone/xform/">http://bunnyherolabs.com/iphone/xform/</a> on your iPhone or iPod Touch, then click the &#8220;+&#8221; (add bookmark) button and choose &#8220;Add to Home Screen.&#8221; Now you can click on the &#8220;Panorama&#8221; icon on your home screen to see the demo at any time, even when not connected to the internet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bunnyhero.org/2010/01/24/iphone-offline-web-applications-tips-and-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

