Storing entire code in bookmark for offline use

From IPhone Developers' Wiki

Jump to: navigation, search

You don't need to have network access to run web-based applications on the iPhone. By using a data: URL, the entire page content is all in the URL. If you save a bookmark for this URL, you can access page/app even in airplane mode.

data:text/html;charset=utf-8;base64,YOUR_BASE_64_ENCODED_DATA_GOES_HERE

By putting images inline using data: URLs, you can create pretty rich pages and store them locally.

Here's a quick Perl one-liner to turn HTML into a data: URL.

perl -0777 -e 'use MIME::Base64; $text = <>; $text = encode_base64($text); $text =~ s/\s+//g; print "data:text/html;charset=utf-8;base64,$text\n";'

By making these links programmatically, you even have an ugly hack to do persistent storage on the iPhone. Just encapsulate your app and its state in its URL.

Personal tools