Phonegap and Titanium Mobile compared in 2011
HTML5 WebSQL databases are currently available in Safari (including Mobile Safari), and the HTML5 FileAPI is implemented in Phonegap.
Unfortunately the WebSQL API isn't prescriptive in a number of areas; there is no canonical method of furnishing your HTML5 offline app with a pre-populated SQL database.
I moved from Phonegap to Appcelerator Titanium shortly after figuring this out (Titanium is much better than Phonegap; although Titanium creates native apps rather than HTML5).
However, it took me quite a while to figure out how to get this to work reliably, and so I didn't want to throw it away.
Here's the solution on github.
<script type="text/javascript">
$(function()
{
{% if messages %}
var messages = ['{{ messages|safeseq|join:"','" }}'];
$.showMessages(messages);
{% endif %}
});
</script>I created this jQuery plugin to support multiple messages, and now it works pretty well with Django's contrib.messages.
Download this jQuery plugin from github.com
The foillowing is an excerpt from the Google JavaScript style guide:
The ability to create closures is perhaps the most useful and often overlooked feature of JS.
One thing to keep in mind, however, is that a closure keeps a pointer to its enclosing scope. As a result, attaching a closure to a DOM element can create a circular reference and thus, a memory leak. For example, in the following code:
function foo(element, a, b) { element.onclick = function() { /* uses a and b */ }; }the function closure keeps a reference to
element,a, andbeven if it never useselement. Sinceelementalso keeps a reference to the closure, we have a cycle that won't be cleaned up by garbage collection. In these situations, the code can be structured as follows:function foo(element, a, b) { element.onclick = bar(a, b); } function bar(a, b) { return function() { /* uses a and b */ } }
I expect this is by far the most commonly made Javascript memory leak.