<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>SitePen Blog</title>
	<atom:link href="http://www.sitepen.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepen.com/blog</link>
	<description>SitePen Services and notes about Dojo, DWR, Cometd, JavaScript, and the Web</description>
	<lastBuildDate>Sun, 31 Jan 2010 14:18:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Efficient Lazy Loading of a Tree</title>
		<link>http://www.sitepen.com/blog/2010/01/27/efficient-lazy-loading-of-a-tree/</link>
		<comments>http://www.sitepen.com/blog/2010/01/27/efficient-lazy-loading-of-a-tree/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 16:36:15 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[ajax]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=753</guid>
		<description><![CDATA[Dojo 1.4 sports a fantastic tree widget, complete with ARIA compliance, keyboard accessibility, and internationalization (including right-to-left layout for appropriate countries and languages).  For large tree data sets, we want to be able to only load the necessary data for the visible nodes of the tree.  As a user expands a node, we [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/11/21/effective-use-of-jsonreststore-referencing-lazy-loading-and-more/' rel='bookmark' title='Permanent Link: Effective use of JsonRestStore: Referencing, Lazy Loading, and more'>Effective use of JsonRestStore: Referencing, Lazy Loading, and more</a></li><li><a href='http://www.sitepen.com/blog/2008/12/18/more-query-and-caching-power-for-data-stores-clientfilter-jsonquery-and-jsonqueryreststore/' rel='bookmark' title='Permanent Link: More Query and Caching Power for Data Stores: ClientFilter, JsonQuery, and JsonQueryRestStore'>More Query and Caching Power for Data Stores: ClientFilter, JsonQuery, and JsonQueryRestStore</a></li><li><a href='http://www.sitepen.com/blog/2008/06/13/restful-json-dojo-data/' rel='bookmark' title='Permanent Link: RESTful JSON + Dojo Data'>RESTful JSON + Dojo Data</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dojotoolkit.org/">Dojo</a> 1.4 sports a fantastic <a href="http://docs.dojocampus.org/dijit/Tree">tree widget</a>, complete with <a href="http://www.w3.org/WAI/intro/aria">ARIA</a> compliance, keyboard accessibility, and internationalization (including right-to-left layout for appropriate countries and languages).  For large tree data sets, we want to be able to only load the necessary data for the visible nodes of the tree.  As a user expands a node, we then want to load the children of that node.  Ideally, we only want to make one HTTP request per expansion for optimal performance.  Historically, effective lazy loading has been a challenge, but some recent additions will make it much easier to utilize efficient lazy loading mechanisms in the tree.</p>
<p><span id="more-753"></span></p>
<p>The Dojo tree widget supports lazy loading, but it typically connects to a Dojo data store for all its data through a model-store adapter.  Consequently, the tree itself does not define the actual data loading mechanism, as that is up to the store.  The tree merely requests data from the store as needed.  However, the <a href="http://docs.dojocampus.org/dojox/data/JsonRestStore">JsonRestStore</a> fully supports <a href="http://www.sitepen.com/blog/2008/11/21/effective-use-of-jsonreststore-referencing-lazy-loading-and-more/">lazy loading</a> with a well defined mechanism for retrieving deferred data from the server.  When the JsonRestStore is used with the tree widget, it makes it possible to lazy load nodes in the tree as nodes are expanded. JsonRestStore supports lazy loading by using <a href="http://www.sitepen.com/blog/2008/06/17/json-referencing-in-dojo/">JSON referencing</a>, whereby items can be referenced from other properties and arrays and the full item can later be retrieved when needed (with <code>loadItem</code>). </p>
<p>The model-store adapter now in Dojo 1.4 and later supports an option for a loading mechanism that facilitates single requests per node expansion.  Previously (in 1.3), when a node was expanded the tree would request all the children and if any of the children had not been loaded, the tree would request that each child&#8217;s data item be fully loaded (this is done to ensure that each child has a label and information about whether or not it has children so the child nodes can be properly rendered) resulting in a request for each child of the expanded node, which is clearly inefficient.  However, now when the model&#8217;s <code>deferItemLoadingUntilExpand</code> property is set to true, the tree will not attempt to load all of the children, but rather will only load the item for the expanded node if needed.  This allows us to leverage the JsonRestStore&#8217;s support for partially loaded items.  When a node is expanded and the item is loaded, the server can provide a JSON representation of the item which includes references to the children, and a partial set of properties for each child, which can include the label and children information for proper rendering.  Each of these children can then be fully loaded when they are expanded (with their partial children objects). With this strategy, each node expansion will rely on only a single HTTP request.</p>
<p>Let&#8217;s take a look at how to build a lazy loaded tree with the JsonRestStore.  We begin by creating a store:</p>
<div class="dean_ch" style="white-space: wrap;">myStore = <span class="kw2">new</span> dojox.<span class="me1">data</span>.<span class="me1">JsonRestStore</span><span class="br0">&#40;</span><span class="br0">&#123;</span>target:<span class="st0">&quot;tree/&quot;</span>, labelAttribute:<span class="st0">&quot;name&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Now, we will create the model adapter for the tree to access the store.  This is where we use the new <code>deferItemLoadingUntilExpand</code> property:</p>
<div class="dean_ch" style="white-space: wrap;">myModel = <span class="kw2">new</span> dijit.<span class="me1">tree</span>.<span class="me1">ForestStoreModel</span><span class="br0">&#40;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; store: myStore,<br />
&nbsp; &nbsp; &nbsp; &nbsp; deferItemLoadingUntilExpand: <span class="kw2">true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; query: <span class="st0">&quot;root&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; childrenAttrs: <span class="br0">&#91;</span><span class="st0">&quot;children&quot;</span><span class="br0">&#93;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Next, we can create a tree:</p>
<div class="dean_ch" style="white-space: wrap;">myTree = <span class="kw2">new</span> dijit.<span class="me1">Tree</span><span class="br0">&#40;</span><span class="br0">&#123;</span>model: myModel<span class="br0">&#125;</span>, treeNode<span class="br0">&#41;</span>;<br />
myTree.<span class="me1">startup</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
<p>Now, we can build our data that is supplied from the server.  The first request that the JsonRestStore will make to the server will be a request for the top level nodes (the children of the root).  The tree will make the initial request using the query provided to the model, and the JsonRestStore will combine that with the target.  In this case, the request will be made to the path &#8220;tree/root&#8221;.  Leveraging the partial loading support in JsonRestStore, we can serialize references to each of the items that will be children of the root node in the response, and only include the properties necessary to render these nodes (label and children info):</p>
<div class="dean_ch" style="white-space: wrap;">request:<br />
GET <span class="re0">/tree/</span>root<br />
response:<br />
<span class="br0">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> $ref: <span class="st0">&#8216;node1&#8242;</span>, <span class="kw3">name</span>:<span class="st0">&#8216;node1&#8242;</span>, children:<span class="kw2">true</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> $ref: <span class="st0">&#8216;node2&#8242;</span>, <span class="kw3">name</span>:<span class="st0">&#8216;node2&#8242;</span><span class="br0">&#125;</span>,<br />
<span class="br0">&#93;</span></div>
<p>This provides sufficient information to render the top level of the tree, as well as the link information for retrieving the full representation of each item.  We don&#8217;t need to actually include the children, just the presence of a children property will indicate to the Tree that the node is expandable and an expansion icon will be included. Now when a user clicks on one of these nodes, the tree will ask the JsonRestStore to load the item and the JsonRestStore will request the resource for the URI specified by the <code>$ref</code> property. In this case, it will request <code>node1</code>.  This URI is interpreted relative to the target URI of the store, so in this case, the JsonRestStore will request &#8220;tree/node1&#8243;.  Your server can then respond:</p>
<div class="dean_ch" style="white-space: wrap;">request:<br />
GET <span class="re0">/tree/</span>node1<br />
response:<br />
<span class="br0">&#123;</span> id: <span class="st0">&#8216;node1&#8242;</span>, <span class="kw3">name</span>:<span class="st0">&#8216;node1&#8242;</span>, someProperty:<span class="st0">&#8217;somePropertyA&#8217;</span>, children:<span class="br0">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> $ref: <span class="st0">&#8216;node1.1&#8242;</span>, <span class="kw3">name</span>: <span class="st0">&#8216;node1.1&#8242;</span>, children: <span class="kw2">true</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span> $ref: <span class="st0">&#8216;node1.2&#8242;</span>, <span class="kw3">name</span>: <span class="st0">&#8216;node1.2&#8242;</span><span class="br0">&#125;</span><br />
<span class="br0">&#93;</span><span class="br0">&#125;</span></div>
<p>Here we see the full representation of <code>node1</code>.  This not only includes the name, but may include additional properties that are used in other application logic.  We also include an array that lists all the children of this item.  Once again we use partial representations of these children to minimize the data transferred over the wire to the client.  Whenever any of these children are expanded the process will be repeated and another request will be made to the server for the full representation of that child.</p>
<p><img src='http://www.sitepen.com/blog/wp-content/uploads/2009/09/lazy-tree.png' alt='lazy-tree.png' /></p>
<p>The example code for lazy loaded trees is available in Dojo at <a href="http://download.dojotoolkit.org/release-1.4.0/dojo-release-1.4.0/dijit/tests/Tree_with_JRS.html">/dijit/tests/Tree_with_JRS.html</a>.</p>
<p>If you are updating data in the store, you should be aware of one more tip when using the Tree with the JsonRestStore.  By default, the ForestStoreModel adapter will re-query the top nodes on every onNew notification event and every onDelete event that involves a top level item.  This can result in queries to the server even though the server has not yet been sent all changes.  This makes top level additions essentially disappear when the re-query takes place.  You may need to override the _onNewItem and _onDeleteItem to provide your own logic about where new and deleted items should be placed in the hierarchy.</p>
<p>Another powerful feature of the referencing capabilities of JsonRestStore is that individual items can be referenced from multiple parent items.  Consequently an item could exist in multiple places in the tree, under different parents.</p>
<p>Together, the Tree and the JsonRestStore provide a powerful combination for lazy loading data that allows for large extensive hierarchical data to be displayed without large upfront data transfers. The JsonRestStore&#8217;s partial loading support can be leveraged so that we can perform lazy loading with a single request per expansion.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/11/21/effective-use-of-jsonreststore-referencing-lazy-loading-and-more/' rel='bookmark' title='Permanent Link: Effective use of JsonRestStore: Referencing, Lazy Loading, and more'>Effective use of JsonRestStore: Referencing, Lazy Loading, and more</a></li><li><a href='http://www.sitepen.com/blog/2008/12/18/more-query-and-caching-power-for-data-stores-clientfilter-jsonquery-and-jsonqueryreststore/' rel='bookmark' title='Permanent Link: More Query and Caching Power for Data Stores: ClientFilter, JsonQuery, and JsonQueryRestStore'>More Query and Caching Power for Data Stores: ClientFilter, JsonQuery, and JsonQueryRestStore</a></li><li><a href='http://www.sitepen.com/blog/2008/06/13/restful-json-dojo-data/' rel='bookmark' title='Permanent Link: RESTful JSON + Dojo Data'>RESTful JSON + Dojo Data</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/27/efficient-lazy-loading-of-a-tree/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting Started With Pintura</title>
		<link>http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/</link>
		<comments>http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/#comments</comments>
		<pubDate>Mon, 25 Jan 2010 08:07:20 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[CommonJS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Persevere]]></category>
		<category><![CDATA[Persev]]></category>
		<category><![CDATA[Persevere 2.0]]></category>
		<category><![CDATA[pintura]]></category>
		<category><![CDATA[Server-Side JavaScript]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=904</guid>
		<description><![CDATA[Pintura is a REST-style web framework that utilizes a layered approach to application development that facilitates straightforward, well-designed rich internet applications. Pintura forms the core web framework for Persevere 2.0, and consists of a powerful data modeling and persistence framework called Perstore, in combination with a REST-style web framework. You can read more about the [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/22/introducing-pintura/' rel='bookmark' title='Permanent Link: Introducing Pintura'>Introducing Pintura</a></li><li><a href='http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/' rel='bookmark' title='Permanent Link: CommonJS/JSGI: The Emerging JavaScript Application Server Platform'>CommonJS/JSGI: The Emerging JavaScript Application Server Platform</a></li><li><a href='http://www.sitepen.com/blog/2008/07/23/getting-started-with-persevere-using-dojo/' rel='bookmark' title='Permanent Link: Getting Started with Persevere Using Dojo'>Getting Started with Persevere Using Dojo</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/kriszyp/pintura/">Pintura</a> is a REST-style web framework that utilizes a layered approach to application development that facilitates straightforward, well-designed rich internet applications. Pintura forms the core web framework for Persevere 2.0, and consists of a powerful data modeling and persistence framework called <a href="http://github.com/kriszyp/perstore/">Perstore</a>, in combination with a REST-style web framework. You can <a href="http://www.sitepen.com/blog/2010/01/22/introducing-pintura/">read more about the goals and principles behind Pintura</a>, but here we will look at how to get started writing applications.</p>
<p>Pintura-based applications normally consist of server-side data models with three layers: data stores, store models, and model facets. On top of this, different representation handlers (for serializing data to different formats) can be defined, but Pintura comes with a good set of these ( including JSON, JavaScript, multipart, and Atom), so usually that is not necessary. This provides a well-structured separation of concerns, distinguishing storage configuration (data stores), core data logic (models), varying capabilities of access to the data (facets), and data serialization (representations). Perhaps the easiest way to understand this approach to take a look at an example application.</p>
<p><span id="more-904"></span></p>
<p>Naturally we need to install Pintura first. Pintura is JavaScript based and can run on various <a href="http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/">CommonJS JavaScript servers</a> including <a href="http://nodejs.org/">Node</a> and <a href="http://narwhaljs.org/">Narwhal</a>/<a href="http://jackjs.org/">Jack</a>, and the various engines they can run on. <a href="http://docs.persvr.org/pintura-documentation/installation">The Pintura installation process is described here</a>.</p>
<p>A basic Pintura application is very easy to create. If we start by making a copy of <code>/template/</code>, we can create an application with a server-side model class by simply adding this to the <a href="http://github.com/kriszyp/pintura/blob/master/template/lib/app.js"><code>lib/app.js</code></a>:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> Model = require<span class="br0">&#40;</span><span class="st0">&quot;model&quot;</span><span class="br0">&#41;</span>.<span class="me1">Model</span>;<br />
Model<span class="br0">&#40;</span><span class="st0">&quot;MyData&quot;</span>, <span class="kw2">null</span>, <span class="br0">&#123;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Once we start up our server for this application, we now have the full <a href="http://docs.persvr.org/documentation/http-rest">Persevere HTTP/REST interface</a> for creating, querying, updating, and deleting objects from the MyTable model. We have everything we need on the server to write a web client application, which can utilize REST methods like GET, PUT, POST, and DELETE, (as well as JSON-RPC) to interact with the server model class to store and query data. We get an enormous amount of functionality for free, including cross-site capabilities (<a href="http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/">JSONP</a>, <a href="http://www.sitepen.com/blog/2008/07/22/windowname-transport/">window.name</a>, and <a href="http://www.w3.org/TR/access-control/">CORS</a> support), <a href="http://en.wikipedia.org/wiki/Cross-site_request_forgery">cross-site request forgery</a> protection, authentication, conditional request handling, and more.</p>
<p>However, most applications will require more server-side logic than simply a generic data store. Generally, application code will be written as model and facet definitions using Pintura&#8217;s persistence framework (Perstore). With this framework, we can define handlers for different aspects of the object&#8217;s interaction and lifecycle, such as <code>get</code>, <code>put</code>, and <code>delete</code> handlers. We can define data integrity contracts by adding JSON schema constraints in <a href="http://www.sitepen.com/blog/2008/11/17/evolving-schemas-with-persevere/">basically the same way as in Persevere 1.0</a> (except our model classes are defined with the <code>Model</code> constructor from the model module rather than a top-level <code>Class</code> constructor, to be more inline with CommonJS and standard web framework terminology). We can define additional methods for the model as well as methods for the persisted object instances (by defining methods on the model prototype), once again using the <a href="http://www.sitepen.com/blog/2008/11/02/using-the-persistent-object-model-in-persevere/">same structure as the first version of Persevere</a>. For example, we could easily add a new method on object instances:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw2">var</span> Model = require<span class="br0">&#40;</span><span class="st0">&quot;model&quot;</span><span class="br0">&#41;</span>.<span class="me1">Model</span>;<br />
Model<span class="br0">&#40;</span><span class="st0">&quot;MyData&quot;</span>, <span class="kw2">null</span>, <span class="br0">&#123;</span><br />
&nbsp; &nbsp; prototype: <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; addFriend: <span class="kw2">function</span><span class="br0">&#40;</span>friend<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">friends</span>.<span class="me1">push</span><span class="br0">&#40;</span>friend<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">save</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Pintura comes with an <a href="http://github.com/kriszyp/pintura/blob/master/example/">example wiki</a>, we will examine how it is constructed to see how we can further understand what it looks like to build an application with Pintura. The example wiki is found in the example folder in the Pintura distribution, and we will break out the various parts and how they fit together.</p>
<p>We will start by looking at the <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/app.js"><code>app.js</code></a> file found in the <code>example/lib</code> directory. This is the entry module which loads the other modules, starting from a user perspective, first defining the application-specific resource representations and user access levels. The <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/access.js"><code>example/lib/access.js</code></a> module defines a set of facets for accessing data, for the different sets of users. For each user, a set of facets is returned and the facet provides the capability through which the user can access the application data. We can then drill down into <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/facet/page.js"><code>example/lib/facet/page.js</code></a> module, which defines how the underlying model class can be accessed through each facet. The <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/model/page.js"><code>example/lib/model/page.js</code></a> defines the core application logic which in turn accesses the data store that provides the low-level interaction with the underlying storage medium.</p>
<p>Let&#8217;s look more closely at each of the levels, starting at the bottom with the store. A data store is the basic entity which allows for RESTful interaction with a storage system. Storage systems can be relational SQL-based databases, document based databases, OS files, remote servers, and so on. The object store API follows the <a href="http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-ObjectStoreSync/">W3C Indexed Database API</a> for an object store. Pintura&#8217;s Perstore framework comes with a variety of data store implementations, including a SQL datastore for Rhino, and a JavaScript/JSON file-based data store. Creating your own store is not difficult, it essentially involves implementing <code>get(id)</code>, <code>put(object, id)</code>, <code>query(query)</code>, and <code>delete(id)</code> functions (and optionally <code>create</code>, <code>transaction</code>, and <code>subscribe</code> for additional functionality). In our example application, we don&#8217;t define any special stores, we will simply use the default store, which out of the box is the <a href="http://github.com/kriszyp/pintura/blob/master/lib/store/js-file.js"><code>js-file</code></a> module, an object store which saves records into a JavaScript/JSON file.</p>
<p>The object store API is not only used at the bottom storage level in Pintura, but the model class and facets also follow the same API for consistency; classes and facets are simply wrappers that expose the same store API, adding their own functionality and/or constraining operations. Model classes act as the gateway to stores, providing the central core logic of the application. Any application data logic that should be enforced for all users should be implemented here. Models do not need to implement the entire store API themselves. Any store method that is implemented simply passes through the underlying object store. An empty class is perfectly valid, and would result in all REST actions being passed through to the object store. In <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/model/page.js"><code>example/lib/model/page.js</code></a>, we can see the <code>put</code> handler is implemented to add a lastModifiedBy property and create a new PageChange instance:</p>
<div class="dean_ch" style="white-space: wrap;">exports.<span class="me1">Page</span> = Model<span class="br0">&#40;</span><span class="st0">&quot;Page&quot;</span>, pageStore, <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; put: <span class="kw2">function</span><span class="br0">&#40;</span>object, id<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; object.<span class="me1">lastModifiedBy</span> = auth.<span class="me1">currentUser</span>.<span class="me1">username</span>;<br />
&#8230;</div>
<p>We can also define the prototype for this class, which allows us to create methods that are available on all instances of the class.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2009/12/PinturaArchitecture1.png" alt="PinturaArchitecture" title="PinturaArchitecture" width="338" height="685" class="alignright size-full wp-image-940" /></p>
<p>At the next layer up, we have the set of facets used to access the Page class. Facets are defined in a similar way to model classes, they follow the store API, wrapping a class, and only methods with specific logic need to be implemented. There are two primary types of facets, restrictive and permissive facets. These differ in how they handle unimplemented methods. A permissive facet will default to passing all actions through to the underlying class. A restrictive facet defaults to only passing retrieval actions (<code>get</code> and <code>query</code>) through, methods have to be explicitly implemented to interact with the class. </p>
<p>In <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/facet/page.js"><code>example/lib/facet/page.js</code></a> we see three facets defined to accommodate different groups of users. The public facet is defined to be restrictive, essentially making the objects read-only for public users. The public facet also defines the query method so that only published pages are accessible. The user facet and admin facet are permissive, allowing all actions on the pages. All of these facets control access to the model class, and in fact, model classes are simply a special permissive facet that applies to data stores.</p>
<p>Continuing back up the stack, the access module can now be understood as the initial logic that determines which facets are available for the authenticated user, so their access is properly controlled.</p>
<p>The initial <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/app.js"><code>example/lib/app.js</code></a> file also defines the custom media module used for generating the HTML for pages. Pintura comes with a good selection of media handlers out of the box; the JavaScript and JSON handlers are the primary use case handlers, allowing objects to easily be accessed through XHR by Ajax applications. Pintura is designed first and foremost for Ajax applications, so normally these will be used most frequently. However, we need a specific HTML handler in this case so that pages can be directly generated as HTML for easy indexing by search engines.</p>
<p>Media handlers are simple to implement. In the <code>example/lib/media/wiki-html.js</code> handler we can see that we just need to define the media type, the quality of the media type (for content negotiation), and the serializer. Bi-direction media handlers can also implement a deserialize method (for handling PUT and POST requests), but this isn&#8217;t needed for our Wiki, all updates to pages will be done through JSON-based XHR requests. The Wiki HTML handler simply uses the the <a href="http://github.com/kriskowal/wiky">wiky package</a> to do the transformation of markup to HTML for us.</p>
<p>By default, Pintura does all the HTTP request handling for you, handling cross-site issues, authentication, transaction management, and converting requests to calls to facets and model classes. However, Pintura is highly modular, actually consisting of about 13 modular middleware appliances, many of which can be used on their own. With these set of modules, one can easily create new HTTP request handling stacks, or reuse individual modules for handling other requests. To see the Pintura stack, you can open up <a href="http://github.com/kriszyp/pintura/blob/master/lib/pintura.js"><code>lib/pintura.js</code></a>, and easily see the different middleware modules that come together in Pintura (this file also lists the set of media type handlers that Pintura registers by default). </p>
<p>For an application running on Jack, the Pintura application stack is defined as the request handler in <a href="http://github.com/kriszyp/pintura/blob/master/example/jackconfig.js"><code>jackconfig.js</code></a> (in Node, it is defined in <a href="http://github.com/kriszyp/pintura/blob/master/example/start-node.js"><code>start-node.js</code></a>). With these startup files we can define our own additional request handling logic, and still defer store related requests to the Pintura handler. This application definition defines static file handlers to simplify development. For the example application, we also created a very simple JSGI middleware module <a href="http://github.com/kriszyp/pintura/blob/master/example/lib/jsgi/redirect-root.js"><code>redirect-root</code></a> that will check for requests to the root path, and redirect to a specific &#8220;root&#8221; wiki page. This middleware wraps the pintura.app request handler, handling the root path, and delegating all other requests to Pintura.</p>
<p>The example wiki gives us a good starting point for beginning to build with Pintura. Much of the persistence, model and facet APIs are defined at the <a href="http://github.com/kriszyp/perstore/">Perstore project page</a>. In the next article in this series, we will look at some more examples of how to leverage the persistence framework and its various stores.</p>
<p>Pintura provides the complete web client-server REST functionality of Persevere combined with a simple, modular, JavaScript-based, facet-oriented architecture, for easy to build to JavaScript applications, with end-to-end consistency, and flexible control and security.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/22/introducing-pintura/' rel='bookmark' title='Permanent Link: Introducing Pintura'>Introducing Pintura</a></li><li><a href='http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/' rel='bookmark' title='Permanent Link: CommonJS/JSGI: The Emerging JavaScript Application Server Platform'>CommonJS/JSGI: The Emerging JavaScript Application Server Platform</a></li><li><a href='http://www.sitepen.com/blog/2008/07/23/getting-started-with-persevere-using-dojo/' rel='bookmark' title='Permanent Link: Getting Started with Persevere Using Dojo'>Getting Started with Persevere Using Dojo</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<series:name><![CDATA[Server-Side JavaScript, Pintura, and Persevere 2.0]]></series:name>
	</item>
		<item>
		<title>Introducing Pintura</title>
		<link>http://www.sitepen.com/blog/2010/01/22/introducing-pintura/</link>
		<comments>http://www.sitepen.com/blog/2010/01/22/introducing-pintura/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:43:40 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[CommonJS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Persevere]]></category>
		<category><![CDATA[narwhal]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[Perse]]></category>
		<category><![CDATA[Persevere 2.0]]></category>
		<category><![CDATA[pintura]]></category>
		<category><![CDATA[rest]]></category>
		<category><![CDATA[Server-Side JavaScript]]></category>
		<category><![CDATA[sofea]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=898</guid>
		<description><![CDATA[Pintura is a CommonJS/JSGI-compliant, server-side JavaScript-based framework for building rich Internet application with the REST architectural style, thin storage-oriented server design, and the consistency of end-to-end JavaScript. The Pintura framework forms the core of Persevere 2.0, and is the first framework built to run on multiple CommonJS platforms like node.js, Narwhal/Jack, and Flusspferd/Zest. It utilizes [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/' rel='bookmark' title='Permanent Link: Getting Started With Pintura'>Getting Started With Pintura</a></li><li><a href='http://www.sitepen.com/blog/2009/11/13/persevere-1-0/' rel='bookmark' title='Permanent Link: Persevere 1.0'>Persevere 1.0</a></li><li><a href='http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/' rel='bookmark' title='Permanent Link: CommonJS/JSGI: The Emerging JavaScript Application Server Platform'>CommonJS/JSGI: The Emerging JavaScript Application Server Platform</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/kriszyp/pintura">Pintura</a> is a <a href="http://commonjs.org/">CommonJS</a>/<a href="http://wiki.commonjs.org/wiki/JSGI/Level0/A">JSGI</a>-compliant, <a href="http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/">server-side JavaScript</a>-based framework for building rich Internet application with the <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm">REST architectural style</a>, <a href="http://www.thinserverarchitecture.com/home">thin storage-oriented server design</a>, and <a href="http://mvalente.eu/2009/11/25/requirements-for-a-modern-web-development-framework/">the consistency of end-to-end JavaScript</a>. The Pintura framework forms the core of Persevere 2.0, and is the first framework built to run on multiple CommonJS platforms like <a href="http://nodejs.org/">node.js</a>, <a href="http://narwhaljs.org/">Narwhal/Jack</a>, and <a href="http://github.com/ashb/Zest">Flusspferd/Zest</a>. It utilizes a layered approach to application development that facilitates straightforward, modular web applications. </p>
<p>Pintura is <strong>not</strong> a traditional MVC web server framework, which often conflate presentation and interaction concerns across the client and server, but rather follows the <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_2">REST prescription</a> of maintaining simple storage and serialization oriented server also known as <a href="http://www.thinserverarchitecture.com/home">thin server architecture</a> or <a href="http://bittwiddler.wordpress.com/2008/05/04/sofea-is-beautiful/">SOFEA</a>. Pintura is designed <a href="http://www.sitepen.com/blog/2008/07/18/clientserver-model-on-the-web/">to cleanly separate the concerns of presentation and interaction on the client, and storage and model logic concerns on the server</a>. This design fits perfectly with comprehensive JavaScript frameworks like <a href="http://www.dojotoolkit.org/">Dojo</a>, <a href="http://www.generalinterface.org/">General Interface</a>, <a href="http://cappuccino.org/">Cappuccino</a>, YUI, and ExtJS that provide <a href="http://www.sitepen.com/blog/2009/08/28/mvc-in-the-browser/">client-side MVC</a>. In particular, Dojo has excellent support for <a href="http://docs.dojocampus.org/dojox/data/JsonRestStore">standards-based JSON REST interaction</a> that matches perfectly with this server-side framework.</p>
<p><span id="more-898"></span></p>
<p>The core design principles behind Pintura:</p>
<ul>
<li>Standards should be leveraged as much as possible to maximize interoperability with other projects, and facilitate freedom in composing web applications with the tools of choice. Pintura is based on <a href="http://www.ietf.org/rfc/rfc2616.txt">RFC 2616 (HTTP/REST)</a>, <a href="http://tools.ietf.org/html/draft-zyp-json-schema-01">JSON Schema</a>, <a href="www.commonjs.org/">CommonJS</a>, JSGI, JSON-RPC, and other interoperable standards.</li>
<li>Presentation and data model logic should be properly separated such that clients can provide the user interface and servers can handle storage and application modeling logic. One should be able to develop multiple web clients for a given application data server.</li>
<li>Storage and data processing concerns should be separated, with <a href="http://www.vldb.org/conf/1997/P266.PDF">pluggable storage options that can easily be switched and combined</a> (such MongoDB plus a MySQL database).
<li>The best option choice between configuration and convention is neither. Integration between different entities without dependence upon certain programming patterns (convention or configuration) is optimal.</li>
<li>End-to-end consistency in data (JSON/JavaScript) handling provides the smoothest communication and interaction from client to server and back.</li>
<li>The most common cases, like standard CRUD style applications, should be very easy, while still making it possible to build more unusual or sophisticated applications.</li>
<li>A framework should be simple enough to read the source and easily extend or modify. Applications and frameworks should be organized into layers of functionality.</li>
<li>Utilize object-capability design for security to allow for flexible security design while protecting against confused deputy style vulnerabilities.</li>
<li>Full support throughout for <a href="http://en.wikipedia.org/wiki/Futures_and_promises">promises</a>, providing asynchronous functionality (used extensively by Node), while preserving clean encapsulated interfaces.</li>
</ul>
<h2>Improvements over Persevere 1.0</h2>
<p>The <a href="http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/">server-side JavaScript community has dramatically changed</a> since Persevere development started. There have been numerous exciting new server-side projects that have started like node.js, flusspferd, and Narwhal, utilizing the new generation of advanced high-performance JavaScript engines like <a href="http://code.google.com/p/v8/">V8</a>, <a href="https://wiki.mozilla.org/JavaScript:TraceMonkey">TraceMonkey</a>, and <a href="http://webkit.org/blog/189/announcing-squirrelfish/">JavaScriptCore</a>. Persevere&#8217;s main focus is on enabling efficient client server interaction and for well-structured web application development, and matching this functionality with powerful new platforms is a great fit.</p>
<p>In many ways, Pintura represents a simplification of Persevere. With an entirely JavaScript-based modular design, it is very easy to dig in and understand how it works, and the complicated Java-JavaScript bridges have been eliminated. The central request handling mechanism is composed of about 13 middleware modules that can easily be rearranged and used on their own. From the ground up, Pintura has a simple, minimal, direct approach to providing REST functionality.</p>
<p>There are numerous other improvements over Persevere 1.0. Pintura introduces a new security system that is based on the object capability model and is therefore much more flexible and powerful than the previous purely role-based mechanism. Much scientific research has pointed to the superiority of capability based design and how it avoids <a href="http://waterken.sourceforge.net/aclsdont/current.pdf">dangerous confused deputy issues</a>. Pintura utilizes &#8220;facets&#8221; (also known as proxies) to provide fine-grained access control to different stored objects. Each facet defines what actions are available for objects, with the flexibility of programmatic guard functions. In the end, security is essentially as simple as defining what facets are available for given users, and then defining what actions the facets allow.</p>
<p>Pintura also has moved to implementing the W3C proposed standard <a href="http://dev.w3.org/2006/webapi/WebSimpleDB/">Indexed Database APIs</a> object store interface for all data stores. Pintura is based around the <a href="http://github.com/kriszyp/perstore">Perstore persistence library</a>, which implements this simple API consisting of a REST-style interface. The stores expose <code>get</code>, <code>put</code>, and <code>delete</code> methods and is used at multiple levels in the framework for simplicity and consistency, including for facets, model classes, as well as lower level object stores. Furthermore, additional functionality is easily applied to stores with provided store wrappers that add support for inheritance, caching, replication, event notification and more. Not only that, but with the interface likely to be implemented in browsers soon, this API will provide true end-to-end consistency.</p>
<p>Pintura has also embraced a much more asynchronous oriented design. JavaScript in the browser uses shared-nothing event loop concurrency, and server side projects like Node and Narwhal are following suit. This not only improves client-server consistency, but there is compelling evidence that suggests that <a href="http://blog.webfaction.com/a-little-holiday-present">event-based design performs and scales much better</a> than traditional thread-based web servers. One of the major challenges of event-based systems is the encapsulation of functionality when dealing with callbacks, but promises are used extensively to greatly simplify working with asynchronous code.</p>
<p>Pintura also leverages the link relation definitions specified by the <a href="http://tools.ietf.org/html/draft-zyp-json-schema">JSON schema specification</a>  that is now a submitted Internet-Draft. Link relations superset the functionality of JSON referencing, and allow for much cleaner, more flexible referencing syntax. This further advances the flexibility of a loosely coupled hyperlink-driven REST architecture.</p>
<p>A core feature of Pintura is now content negotiation, following the REST architectural design of permitting multiple representations of a resource. Resources effectively are persistable JavaScript objects, and representations allows these objects to be serialized and deserialized in multiple formats. Pintura has excellent RFC 2616 conformance to content negotiation and provides a number of out of the box media type handlers, such JSON, JavaScript, CSV, and more, while making it easy to create new custom media type handlers.</p>
<p>Finally, Pintura uses greatly <a href="http://groups.google.com/group/json-query/browse_thread/thread/a7255cc47ef484be">simplified querying syntax</a>. It continues to provide powerful URL-based querying, but the format is simplified to work easily with standard HTML form URL-encoding, aligns with the <a href="tools.ietf.org/html/draft-nottingham-atompub-fiql">feed item query language</a>, and has an easy to use and extensible call syntax. Pintura provides a parsing mechanism to help developers implement their own custom query handlers.</p>
<h2>Role in Persevere 2.0</h2>
<p>Persevere 2.0 is not a single monolithic project, but will be a distribution of several web stack configurations composed of various components including Pintura, Perstore, and <a href="http://www.sitepen.com/blog/2009/01/14/store-explorer/">the store explorer</a>. Pintura and Perstore are still alpha stage software, but the Persevere 2.0 system is shaping up quickly.</p>
<p><img src="http://www.sitepen.com/blog/wp-content/uploads/2010/01/PinturaStack.png" alt="PinturaStack" title="PinturaStack" width="574" height="421" class="size-full wp-image-993" /></p>
<h2>The Next Web Stack</h2>
<p>Pintura brings together the cumulative advances of modern JavaScript and web architecture design patterns, including object capability based security, event-driven flow, immutable promises, JSON Schema, REST style, and thin server architecture. Coupled with the powerful new CommonJS platforms and remarkably fast JavaScript engines, this framework fulfills a critical role in the next generation web application stack, and is built to adapt to your JS platform of choice. The next article in this series will explore how to get started with Pintura.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/' rel='bookmark' title='Permanent Link: Getting Started With Pintura'>Getting Started With Pintura</a></li><li><a href='http://www.sitepen.com/blog/2009/11/13/persevere-1-0/' rel='bookmark' title='Permanent Link: Persevere 1.0'>Persevere 1.0</a></li><li><a href='http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/' rel='bookmark' title='Permanent Link: CommonJS/JSGI: The Emerging JavaScript Application Server Platform'>CommonJS/JSGI: The Emerging JavaScript Application Server Platform</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/22/introducing-pintura/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<series:name><![CDATA[Server-Side JavaScript, Pintura, and Persevere 2.0]]></series:name>
	</item>
		<item>
		<title>Managing Widget Templates in Dojo 1.4</title>
		<link>http://www.sitepen.com/blog/2010/01/20/managing-widget-templates-in-dojo-1-4/</link>
		<comments>http://www.sitepen.com/blog/2010/01/20/managing-widget-templates-in-dojo-1-4/#comments</comments>
		<pubDate>Wed, 20 Jan 2010 19:06:00 +0000</pubDate>
		<dc:creator>sfoster</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=985</guid>
		<description><![CDATA[This article introduces dojo.cache and presents a technique for externalizing your widget templates in swappable configuration files, where they can be referenced by a custom templateKey widget property.
Introducing dojo.cache
Dojo 1.4 adds a new core utility called dojo.cache. To appreciate it we first have to review how Dijit&#8217;s templatePath works. When you define a _Templated widget [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/06/24/creating-dojo-widgets-with-inline-templates/' rel='bookmark' title='Permanent Link: Creating Dojo Widgets with Inline Templates'>Creating Dojo Widgets with Inline Templates</a></li><li><a href='http://www.sitepen.com/blog/2007/11/02/html-widget-prototyping-with-the-dojo-toolkit/' rel='bookmark' title='Permanent Link: HTML Widget Prototyping with the Dojo Toolkit'>HTML Widget Prototyping with the Dojo Toolkit</a></li><li><a href='http://www.sitepen.com/blog/2008/04/02/dojo-mini-optimization-tricks-with-the-dojo-toolkit/' rel='bookmark' title='Permanent Link: Dojo-Mini: Optimization Tricks with the Dojo Toolkit'>Dojo-Mini: Optimization Tricks with the Dojo Toolkit</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>This article introduces <code>dojo.cache</code> and presents a technique for externalizing your widget templates in swappable configuration files, where they can be referenced by a custom <code>templateKey</code> widget property.</p>
<h3>Introducing dojo.cache</h3>
<p>Dojo 1.4 adds a new core utility called <code>dojo.cache</code>. To appreciate it we first have to review how Dijit&#8217;s <code>templatePath</code> works. When you define a <code>_Templated</code> widget with a <code>templatePath</code> property, the content from that URL is fetched the first time you instantiate the widget, and made available as a string. All subsequent instances get the cached string. Furthermore, when you run a build, your <code>templatePath</code>s get replaced with <code>templateString</code>s and their content is inlined into the output from the build. This improves performance considerably by removing those synchronous XHR requests, while remaining transparent to the developer.  </p>
<p><code>dojo.cache</code> generalizes this pattern, making the same functionality available from Dojo Core&mdash;synchronous, cached content retrieval that gets inlined during the build.  <a href="http://docs.dojocampus.org/dojo/cache">dojo.cache usage</a> is much like <code>dojo.moduleUrl</code>: </p>
<div class="dean_ch" style="white-space: wrap;">dojo.<span class="me1">require</span><span class="br0">&#40;</span><span class="st0">&quot;dojo.cache&quot;</span><span class="br0">&#41;</span>;<br />
my.<span class="me1">stringResource</span> = dojo.<span class="me1">cache</span><span class="br0">&#40;</span><span class="st0">&quot;module.path&quot;</span>, <span class="st0">&quot;relative.path.html&quot;</span> <span class="br0">&#41;</span>;</div>
<p><span id="more-985"></span></p>
<h3>Runtime configuration</h3>
<p>You&#8217;ll find many uses for <code>dojo.cache</code>. The ability to define and cache strings was immediately useful for me in the context of runtime configuration files. This is a fairly common technique in which you define and load modules ahead of most of the components to your app, to externalize constants and properties for the application that you don&#8217;t want to hard-code into each component. So, you might have something like this:</p>
<div class="dean_ch" style="white-space: wrap;">dojo.<span class="me1">provide</span><span class="br0">&#40;</span><span class="st0">&quot;myapp.defaultConfig&quot;</span><span class="br0">&#41;</span>;<br />
<span class="co1">// dojo.require(&quot;myapp.defaultConfig&quot;) populates myapp.config </span><br />
<span class="co1">// with messages with a laid-back informal tone</span><br />
myapp.<span class="me1">config</span> = &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loadingText: <span class="st0">&quot;We&#8217;re loading that for you, won&#8217;t be a sec.&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; loadErrorText: <span class="st0">&quot;Ugh, that didn&#8217;t work out. Sorry.&quot;</span><br />
<span class="br0">&#125;</span>;</div>
<p>&#8230;and a variation: </p>
<div class="dean_ch" style="white-space: wrap;">dojo.<span class="me1">provide</span><span class="br0">&#40;</span><span class="st0">&quot;myapp.formalConfig&quot;</span><span class="br0">&#41;</span>;<br />
<span class="co1">// dojo.require(&quot;myapp.formalConfig&quot;) populates myapp.config</span><br />
<span class="co1">// with messages with a more formal tone</span><br />
myapp.<span class="me1">config</span> = &nbsp;<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loadingText: <span class="st0">&quot;Fetching requested resource&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; loadErrorText: <span class="st0">&quot;Error loading requested resource. Please accept our apologies.&quot;</span><br />
<span class="br0">&#125;</span>;</div>
<p>In this example, switching the &#8220;tone&#8221; in your app is as simple as switching the one line that requires your config. Your code can use e.g. <code>this.attr("content", myapp.config.loadingText)</code> without having to know or care which variation it is supposed to be using. </p>
<h3>Template configuration</h3>
<p>Now with <code>dojo.cache</code>, we can manage templates in the same way, using object paths which can be looked up and requested at runtime during development, and inlined by the build for production:  </p>
<div class="dean_ch" style="white-space: wrap;">myapp.<span class="me1">config</span> = <span class="br0">&#123;</span> <br />
&nbsp; templates: <span class="br0">&#123;</span><br />
&nbsp; &nbsp; someWidget: dojo.<span class="me1">cache</span><span class="br0">&#40;</span><span class="st0">&quot;myapp.resources&quot;</span>, <span class="st0">&quot;someWidget.html&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; otherWidget: dojo.<span class="me1">cache</span><span class="br0">&#40;</span><span class="st0">&quot;myapp.alternateResources&quot;</span>, <span class="st0">&quot;otherWidget.html&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; collapsiblePanel: dojo.<span class="me1">cache</span><span class="br0">&#40;</span><span class="st0">&quot;dijit.templates&quot;</span>, <span class="st0">&quot;TitlePane.html&quot;</span><span class="br0">&#41;</span>,<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
<p>The config lets us retrieve template strings by using a look-up like myapp.config.templates.someWidget. With Dojo, we can treat these types of object paths as strings and use dojo.getObject to receive the value they represent. In this sense the object path is like an address&mdash;it gives us the ability to reference a variable and potentially a long string like a template with a short, symbolic one. I use these configuration properties by referencing them in a (new and custom) <code>templateKey</code> widget property. The key provides a level of indirection that enables you to pull template management outside of your widget definition entirely. It looks like this: </p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc2"><a href="http://december.com/html/4/element/div.html"><span class="kw2">&lt;div</span></a> dojoType=<span class="st0">&quot;my.SomeWidget&quot;</span> templateKey=<span class="st0">&quot;myapp.config.templates.someWidget&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/div&gt;</span></span></div>
<h3>Template Reuse</h3>
<p>When all that varies between a set of widget classes is the template markup, you can reuse one widget by simply passing the instance a new <code>templateKey</code>, for example:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="sc2"><a href="http://december.com/html/4/element/div.html"><span class="kw2">&lt;div</span></a> dojoType=<span class="st0">&quot;my.SomeWidget&quot;</span> templateKey=<span class="st0">&quot;myapp.config.templates.someWidgetInversed&quot;</span><span class="kw2">&gt;</span></span><span class="sc2"><span class="kw2">&lt;/div&gt;</span></span></div>
<h3>The Implementation</h3>
<p>To make this happen we need to have all widgets use an extended <code>dijit._Templated</code> to put the <code>templateKey</code> property on the prototype, and handle it in the <code>buildRendering</code> step: </p>
<div class="dean_ch" style="white-space: wrap;">dojo.<span class="me1">declare</span><span class="br0">&#40;</span><span class="st0">&quot;myapp._Templated&quot;</span>, dijit._Templated, <span class="br0">&#123;</span><br />
&nbsp; <br />
&nbsp; templateKey: <span class="st0">&quot;&quot;</span>,</p>
<p>&nbsp; buildRendering: <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">templateKey</span><span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">templateString</span> = dojo.<span class="me1">getObject</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">templateKey</span><span class="br0">&#41;</span>; <br />
&nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">inherited</span><span class="br0">&#40;</span><span class="st0">&quot;buildRendering&quot;</span>, arguments<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>.. which gets used by all our custom templated widgets, e.g. </p>
<div class="dean_ch" style="white-space: wrap;">dojo.<span class="me1">declare</span><span class="br0">&#40;</span><span class="st0">&quot;myapp.SomeWidget&quot;</span>, <span class="br0">&#91;</span>dijit._Widget, myapp._Templated<span class="br0">&#93;</span>, <span class="br0">&#123;</span><br />
&nbsp; templateKey: <span class="st0">&quot;myapp.config.templates.someWidget&quot;</span>, <span class="co1">// an optional, default value</span><br />
<span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
<p>Now, when we run our build, the config file you&#8217;ve specified gets the inlined templates, and the <code>templateKey</code> look-up works just as before. We could even <a href="http://www.sitepen.com/blog/2009/02/04/patching-dojo/">monkey-patch</a> this functionality into <code>dijit._Templated</code> and wring yet more goodness from the out-of-the-box Dijit &#038; DojoX widgets. </p>
<h3>Conclusion</h3>
<p>Dijit&#8217;s architecture has always let you override templates, but in practice this has typically necessitated a subclass. The combination of runtime configuration and <code>dojo.cache</code> gives you new, powerful options that keep specifics out of reusable components, while maintaining resources in a manageable way. This is just one new technique that falls out of Dojo 1.4. Would you use it? What have been the highlights of 1.4 for you? </p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/06/24/creating-dojo-widgets-with-inline-templates/' rel='bookmark' title='Permanent Link: Creating Dojo Widgets with Inline Templates'>Creating Dojo Widgets with Inline Templates</a></li><li><a href='http://www.sitepen.com/blog/2007/11/02/html-widget-prototyping-with-the-dojo-toolkit/' rel='bookmark' title='Permanent Link: HTML Widget Prototyping with the Dojo Toolkit'>HTML Widget Prototyping with the Dojo Toolkit</a></li><li><a href='http://www.sitepen.com/blog/2008/04/02/dojo-mini-optimization-tricks-with-the-dojo-toolkit/' rel='bookmark' title='Permanent Link: Dojo-Mini: Optimization Tricks with the Dojo Toolkit'>Dojo-Mini: Optimization Tricks with the Dojo Toolkit</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/20/managing-widget-templates-in-dojo-1-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CommonJS/JSGI: The Emerging JavaScript Application Server Platform</title>
		<link>http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/</link>
		<comments>http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 09:25:33 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[CommonJS]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Persevere]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[Persevere 2.0]]></category>
		<category><![CDATA[pintura]]></category>
		<category><![CDATA[Server-Side JavaScript]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=761</guid>
		<description><![CDATA[CommonJS (formerly known as ServerJS) has become the essential hub around the development of server side JavaScript (SSJS). SSJS for years has suffered from fragmentation, but the CommonJS project has provided the momentum to bring different frameworks together and start building interoperable modules. SSJS is ripe with potential; JavaScript has been soaring in popularity and [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/22/introducing-pintura/' rel='bookmark' title='Permanent Link: Introducing Pintura'>Introducing Pintura</a></li><li><a href='http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/' rel='bookmark' title='Permanent Link: Getting Started With Pintura'>Getting Started With Pintura</a></li><li><a href='http://www.sitepen.com/blog/2009/09/01/narwhal-on-persevere/' rel='bookmark' title='Permanent Link: Narwhal on Persevere'>Narwhal on Persevere</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.commonjs.org/">CommonJS</a> (formerly known as ServerJS) has become the essential hub around the development of server side JavaScript (SSJS). SSJS for years has suffered from fragmentation, but the CommonJS project has provided the <a href="http://arstechnica.com/web/news/2009/12/commonjs-effort-sets-javascript-on-path-for-world-domination.ars">momentum</a> to bring different frameworks together and start building interoperable modules. <a href="http://www.readwriteweb.com/archives/server-side_javascript_back_with_a_vengeance.php">SSJS is ripe with potential</a>; <a href="http://www.tiobe.com/index.php/paperinfo/tpci/JavaScript.html">JavaScript has been soaring in popularity</a> and the <a href="http://www.ecma-international.org/news/PressReleases/PR_Ecma_finalises_major_revision_of_ECMAScript.htm">ECMAScript 5 specification was recently accepted</a>. JavaScript has proven itself as <b>the</b> language of the web&#8217;s client-side (even ActionScript is a derivative of JavaScript). The opportunity to use the same language on both client and server is certainly most realistic and viable with JavaScript as it avoids the need for translation.</p>
<h2>CommonJS</h2>
<p>CommonJS has focused on developing critical APIs for building reusable modules, particularly for server-side JavaScript environment. The server-side is generally based around database interaction, file I/O, HTTP serving, and the generation of data formats and HTML, whereas the client-side is based around DOM manipulation and the browser object model. There are certainly APIs that can be used on both sides, and JavaScript on the client and server invites the reuse of APIs where possible. The <a href="http://www.whatwg.org/specs/web-workers/current-work/">WebWorker</a>, <a href="http://dev.w3.org/2006/webapi/WebSimpleDB/">Indexed Database</a>, and <a href="http://www.w3.org/TR/XMLHttpRequest/">XHR</a> APIs are promising to be enormously beneficial on the server side, and with excellent client server consistency. But still the server side requires special attention, and CommonJS is bringing the needed standards and conventions.</p>
<p><span id="more-761"></span></p>
<p>There have been a number of different areas that CommonJS has invested in for creating the necessary foundation for SSJS. The primary initial effort was in defining the module system, which provides an easy to use system for loading modules and their dependencies, while ensuring that each module is loaded only once. This module system is now very broadly implemented and extensively used by the other subsequent module APIs defined by CommonJS. The module system provides the essential basis for modular library and application development. </p>
<p>CommonJS is working on building up the low-level I/O components, defining the necessary binary data types, the APIs for file interaction, and encoding. There are proposals in place for unit testing, and a number of modules to provide concurrency support. And finally there is a HTTP interface specification known as JSGI.</p>
<h3>Concurrency</h3>
<p>One of the most central characteristics of a runtime is the concurrency approach. The inherent dangers of shared memory threading <a href="http://weblogs.mozillazine.org/roadmap/archives/2007/02/threads_suck.html">are widely understood</a>, and the browsers wisely avoid exposing developers to the low level complications of shared-memory threads, alternately providing shared nothing event-loop concurrency. With the latter approach, data structures are not exposed to preemptive threads that could cause race conditions. Instead, events are queued up, and deterministically executed. Concurrent operations are handled with WebWorkers, in separate memory spaces, with the ability to communicate to other workers with message passing.</p>
<p>The CommonJS group defines APIs, so it is beyond the scope of CommonJS to dictate the concurrency model used by servers, but there is general consensus recommending that JavaScript-based servers utilize shared-nothing event loop concurrency, and CommonJS APIs are built to support this model. The CommonJS wiki includes proposals for exposing the <a href="http://dev.w3.org/html5/workers/">WebWorker API</a> through a <a href="http://wiki.commonjs.org/wiki/Worker">worker module</a>, and for exposing controls for the event loop with the <a href="http://wiki.commonjs.org/wiki/Reactor">event-queue module</a>.</p>
<h3>Promises</h3>
<p>One key abstraction that is extremely useful for event-based systems is a promise. A promise is an abstraction that encapsulates the execution of an asynchronous action and its subsequent value that it returns. A promise can be thought of as representing the result of an asynchronous computation. The promise will receive the value returned by the call when it is finished, and acts as a placeholder for the returned value. Promises are critical to developing large scale applications that make heavy use of asynchronicity. Using callback-passing for asynchronous actions does not compose well. It is impossible to properly encapsulate functionality, switching an implementation from synchronous to asynchronous breaks APIs and creates complex flows of passing callbacks around to handle return values. With promises, values can be returned just like synchronous functions, and callers can listen for asynchronous results without requiring additional callback-passing APIs.</p>
<p>The promise API in CommonJS is an asynchronous handling system based on the collective experience of the promises in <a href="http://dojotoolkit.org/">Dojo</a>, <a href="http://twistedmatrix.com/trac/">Twisted</a>, and <a href="http://waterken.sourceforge.net/">ref_send</a>. The ref_send promises focus on secure immutable promises, but lacks a reasonable API for promise implementors. Dojo provides a promise API (called <a href="http://docs.dojocampus.org/dojo/Deferred">Deferreds</a>) with convenient chaining support, but has suffered from the use of mutable promises, with side-effect inducing callbacks complicating the data flow. The promise API combines the best of both, providing secure immutable promises with a very simple, easy to implement API for implementors, and full chaining support. The <a href="http://wiki.commonjs.org/wiki/Promises">promise API in CommonJS</a> provides a foundation that implementors can easily extend to provide the convenience functions from Dojo&#8217;s Deferred API as well as ref_send&#8217;s static operators.</p>
<p>An example of using CommonJS promise might look like:</p>
<div class="dean_ch" style="white-space: wrap;">
requestSomeData<span class="br0">&#40;</span><span class="st0">&quot;http://example.com/foo&quot;</span><span class="br0">&#41;</span> <span class="co1">// returns a promise for the response</span><br />
&nbsp; &nbsp; .<span class="me1">then</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>response<span class="br0">&#41;</span><span class="br0">&#123;</span> <span class="co1">// &#8216;then&#8217; is used to provide a promise handler </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> JSON.<span class="me1">parse</span><span class="br0">&#40;</span>response.<span class="me1">body</span><span class="br0">&#41;</span>; <span class="co1">// parse the body</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span> <span class="co1">// returns a promise for the parsed body</span><br />
&nbsp; &nbsp; .<span class="me1">then</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>data<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> data.<span class="me1">price</span>; <span class="co1">// get the price</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span> <span class="co1">// returns a promise for the price</span><br />
&nbsp; &nbsp; .<span class="me1">then</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>price<span class="br0">&#41;</span><span class="br0">&#123;</span> <span class="co1">// print out the price when it is fulfilled</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">print</span><span class="br0">&#40;</span><span class="st0">&quot;The price is &quot;</span> + price<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
&nbsp;</div>
<h2>JSGI: HTTP Gateway</h2>
<p>The <a href="http://wiki.commonjs.org/wiki/JSGI">JavaScript gate interface (JSGI) API</a> has been asymptotically reaching consensus in the CommonJS group, as a standard API for serving HTTP requests through JavaScript application servers. The JSGI provides a very easy to use API for responding to HTTP requests, influenced by the design of WSGI and Rack. A basic JSGI application looks like:</p>
<div class="dean_ch" style="white-space: wrap;">
app = <span class="kw2">function</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">status</span>: <span class="nu0">200</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; headers: <span class="br0">&#123;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; body: <span class="br0">&#91;</span><span class="st0">&quot;Hello World&quot;</span><span class="br0">&#93;</span><br />
&nbsp; &nbsp; <span class="br0">&#125;</span>;<br />
<span class="br0">&#125;</span>;<br />
&nbsp;</div>
<p>JSGI has been intentionally designed to make it easy to write &#8220;middleware&#8221;, modules that exist at different places in the request handling chain to add various forms of functionality. Middleware can include support for cross-domain requests, logging, error handling, special method handling, mapping URLs to different applications, and much more.</p>
<p>Most existing HTTP interfaces were designed around a synchronous model, and have had an extremely difficult time adapting to the asynchronous model, which is essential for efficient Comet support. JSGI on the other hand, has been developed from the ground up with asynchronicity in mind, both to support Comet, and to work properly in an event-based environment. JSGI achieves support for asynchronicity while still maintaining a simple function call and return style by leveraging promises. Here we can see the power of promises, JSGI applications can return a promise to indicate that the response is not yet complete, and no additional callback parameter need to be passed around. With promise support throughout, an asynchronous JSGI app can be as simple as:</p>
<div class="dean_ch" style="white-space: wrap;">
app = <span class="kw2">function</span><span class="br0">&#40;</span>request<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw1">return</span> doSomethingAsynchronous<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">then</span><span class="br0">&#40;</span><span class="kw2">function</span><span class="br0">&#40;</span>result<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">status</span>: <span class="nu0">200</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headers: <span class="br0">&#123;</span><span class="br0">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body: <span class="br0">&#91;</span><span class="st0">&quot;Result &quot;</span>, result<span class="br0">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>;<br />
&nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span>;<br />
&nbsp;</div>
<p>Since JSGI effectively provides a JSON/JavaScript representation of the HTTP protocol, JSGI has powerful opportunities for use in communication outside of just HTTP server handling. JSGI can be used as an API for making HTTP requests as a client (as a promise based alternative to XHR), and can be used as an inter-process/inter-worker protocol. HTTP is almost certainly the most commonly used communication protocol, and the RESTful power of HTTP can easily be leveraged for worker communication with JSGI&#8217;s JSON-based format (that doesn&#8217;t require HTTP parsing).</p>
<h2>Projects</h2>
<p>CommonJS and JSGI are purely API specifications, not implementations. Lets look at some projects that implement these specifications.</p>
<h3>Narwhal/Jack</h3>
<p>Probably the most advanced and mature CommonJS implementation is <a href="http://narwhaljs.org/">Narwhal</a> plus <a href="http://jackjs.org/">Jack</a>. Basically all of the CommonJS APIs are implemented in Narwhal/Jack and/or their forks. Narwhal provides extensive I/O support, a large collection of useful library modules, and a great package management system called tusk with package resource handling built into its module loader. Narwhal is designed for running on various JavaScript platforms and has an intelligently architected layer of abstractions for dealing with different engines.</p>
<p>Narwhal has the most complete engine support for Rhino. Rhino is almost certainly the most popular JavaScript engine for server side JavaScript due to its seamless integration with Java. With Rhino, the virtually limitless expanse of Java libraries are available and easily accessible. While great efforts are being made to important libraries in other engines, the breadth of libraries that are available through the Rhino&#8217;s Java bridge is not likely to be matched anytime soon. It also comes with a good visual debugger. Rhino is also perhaps the most feature-rich JavaScript implementation available, as it implements most of the <a href="http://www.youtube.com/watch?v=Kq4FpMe6cRs">ECMAScript 5</a> specification and Mozilla&#8217;s <a href="https://developer.mozilla.org/En/New_in_JavaScript_1.8">JavaScript 1.8 features</a>.</p>
<p>Narwhal also runs on JSCore, the JavaScript engine used by Safari. JSCore is a very high-performance engine (second only to V8, perhaps), and consequently there is great potential for high-performance applications running on Narwhal/JSCore.</p>
<p>Jack is a JSGI implementation that has been developed to run on Narwhal, and is also built to run on various web server technologies. Jack has been somewhat of the de facto reference implementation for JSGI, and runs on Simple, CGI, servlet containers (including Jetty and GAE), and others. Older versions of Jack relied on shared memory threading, but with the latest work on Jack, requests are handled with full event loop based shared-nothing concurrency, with request delegation across multiple workers for efficient multi-core utilization.</p>
<h3>Node</h3>
<p><a href="http://nodejs.org/">Node</a> is an exciting project in the SSJS realm, and has received a lot of publicity recently, for good reason. Node builds on the amazingly fast V8 engine and provides important low-level functionality. V8 is one of the fastest dynamic language engines on the planet. Node uses <a href="http://software.schmorp.de/pkg/libev.html">libev</a> for an event-loop based asynchronous I/O model, providing the same type of event-loop shared-nothing concurrency used in Narwhal. However, Node has had a stronger emphasis on trying to provide asynchronous APIs for all I/O operations. By exposing almost all I/O operations as asynchronous events, Node rarely has to block while waiting for I/O, and is able to execute much more efficiently than spreading workloads across multiple blocking threads. The performance advantages to event-loops over threads are <a href="http://blog.webfaction.com/a-little-holiday-present">well-documented</a>. This focus, in combination with the blazing fast V8 engine, promises to place Node as the performance king of dynamic language based application servers.</p>
<p>There are certainly gaps that need to be filled with Node. Node implements CommonJS&#8217;s module system, but does not implement other CommonJS APIs, and has been slow to add better support for interoperability. Node runs its HTTP server and handling on a single process/thread, which means it can&#8217;t utilize multi-cores yet (support for that is coming). Node does not support the JSGI specification; however, it is possible to <a href="http://github.com/kriszyp/jsgi-node">run JSGI on Node with the JSGI-Node adapter</a> that I built.</p>
<p>There are other important things like package support and module reloading that are definitely needed. From my experience, Node does not feel as complete as Narwhal. However, despite these concerns, Node has a lot of potential, and is an exciting project. Node primarily fulfills a role as a low-level JavaScript platform, on which higher level functionality can be built. The Node community is responsive. There is an effort to run Narwhal on top of Node, which would be a powerful combination. </p>
<h3>Ejscript</h3>
<p><a href="http://www.ejscript.org/">Ejscript</a> is a JavaScript platform that extends the JavaScript language with many new constructs. Many of these additions are based on the ECMAScript 4 specification that was eventually abandoned because many implementors felt it was too extensive of a revision of the language. However, many of the features included in ECMAScript 4 that Ejscript implements were technically excellent additions, and may be included in ECMAScript 6. Beyond extra language features, Ejscript boasts a very high performance engine with remarkably low memory footprints, claiming performance that rivals Node with less than a tenth of the memory consumption.</p>
<h3>Persevere</h3>
<p><a href="http://www.persvr.org/">Persevere</a> was one of the first projects to implement the CommonJS module specification. However, the primary goal of the Persevere project is to provide consistent end-to-end data semantics leveraging RESTful architecture. Persevere 1.0 provided CommonJS module support to provide interoperability with other CommonJS libraries, but being a JavaScript platform is beyond the primary scope of the project. With the new array of CommonJS platforms, future Persevere development will now focus on building on top of these new platforms and providing its data persistence, security, REST architecture, Comet notifications, and advanced web communication capabilities for multiple platforms.</p>
<h3>Others</h3>
<p>Mozilla&#8217;s SpiderMonkey engine is also a capable engine for server side JavaScript. <a href="http://flusspferd.org/">Flusspferd</a> is a project to add low-level system functionality to SpiderMonkey and couples with <a href="http://github.com/ashb/Zest">Zest</a> as a JSGI server and <a href="http://juicejs.org/">Juice</a> as a web framework on top.</p>
<p>There are number of other important server-side projects including <a href="http://helma.org/wiki/Helma+NG/">HelmaNG</a>, with high-quality technology that predates CommonJS and now are adapting to work in harmony with the CommonJS ecosystem, but I won&#8217;t cover all of them.</p>
<h3>Web Frameworks</h3>
<p>Some exciting new web frameworks are building on these technologies such as <a href="http://github.com/gmosx/nitro/">Nitro</a>, <a href="http://github.com/nrstott/bogart">Bogart</a>, and <a href="http://juicejs.org/">JuiceJS</a>. Also some platforms come with their own MVC framework such as HelmaNG, and EJScript. However, for many the move to JavaScript has been motivated by investment in rich client interfaces that already have presentation capabilities (the V and C in MVC), so a more modern REST-style, &#8220;thin server architecture&#8221; may be a better fit than traditional server-side MVC frameworks for many next generation JavaScript-based web applications. <a href="http://github.com/kriszyp/pintura">Pintura</a> is the core of the next generation of Persevere, a cross-platform REST-style architecture web framework that is designed specifically for Ajax-style applications that maintain presentation logic on the client separate from the server-side storage concerns. We will cover Pintura in the next article of this series.</p>
<h2>Conclusion</h2>
<p>The combination of improvements and maturation of ECMAScript standards, with the new line of astonishingly fast JavaScript, the Ajax driven interest in JavaScript, the collaborative efforts of CommonJS standards, and the emerging array of server-side JavaScript projects are all coming together to propel server-side JavaScript to the forefront of web application development. It is not unreasonable to expect that the CommonJS APIs implemented with a web stack of the new line of SSJS projects could be the most important new web platform of the next decade.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2010/01/22/introducing-pintura/' rel='bookmark' title='Permanent Link: Introducing Pintura'>Introducing Pintura</a></li><li><a href='http://www.sitepen.com/blog/2010/01/25/getting-started-with-pintura/' rel='bookmark' title='Permanent Link: Getting Started With Pintura'>Getting Started With Pintura</a></li><li><a href='http://www.sitepen.com/blog/2009/09/01/narwhal-on-persevere/' rel='bookmark' title='Permanent Link: Narwhal on Persevere'>Narwhal on Persevere</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/19/commonjsjsgi-the-emerging-javascript-application-server-platform/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<series:name><![CDATA[Server-Side JavaScript, Pintura, and Persevere 2.0]]></series:name>
	</item>
		<item>
		<title>Performance Testing of the Top 100 Sites is Misleading at Best</title>
		<link>http://www.sitepen.com/blog/2010/01/11/performance-testing-of-the-top-100-sites-is-misleading-at-best/</link>
		<comments>http://www.sitepen.com/blog/2010/01/11/performance-testing-of-the-top-100-sites-is-misleading-at-best/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:09:10 +0000</pubDate>
		<dc:creator>Dylan</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[browsers]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=728</guid>
		<description><![CDATA[Recently, a number of performance tests have been released that are based on the performance of the top 100 web sites such as SpriteMe savings, the IE8 100 top sites test results, or the JSMeter research.  These are in direct contrast with tests such as ACID3 which attempt to test the future of the [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/06/09/string-performance-getting-good-performance-from-internet-explorer/' rel='bookmark' title='Permanent Link: String Performance: Getting Good Performance from Internet Explorer'>String Performance: Getting Good Performance from Internet Explorer</a></li><li><a href='http://www.sitepen.com/blog/2008/03/24/why-apple-is-investing-in-webkit-performance/' rel='bookmark' title='Permanent Link: Why Apple is Investing in WebKit Performance'>Why Apple is Investing in WebKit Performance</a></li><li><a href='http://www.sitepen.com/blog/2009/08/10/web-page-global-variable-performance/' rel='bookmark' title='Permanent Link: Web Page Global Variable Performance'>Web Page Global Variable Performance</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Recently, a number of performance tests have been released that are based on the performance of the top 100 web sites such as <a href="http://spriteme.org/results.php?top=100">SpriteMe savings</a>, the <a href="http://blogs.msdn.com/ie/archive/2008/08/26/ie8-performance.aspx">IE8 100 top sites test results</a>, or the <a href="http://research.microsoft.com/apps/pubs/default.aspx?id=115687">JSMeter research</a>.  These are in direct contrast with tests such as ACID3 which attempt to test the future of the web rather than just what&#8217;s possible today.</p>
<p>These efforts are outstanding and highly useful, especially the JSMeter work and their valiant effort to redefine performance tests that are indicative of today&#8217;s web apps.</p>
<p>I completely agree with one of their stated goals:</p>
<blockquote><p>We hope our results will convince the JavaScript community to develop and adopt benchmarks that are more representative of real web applications.</p></blockquote>
<p>However, I disagree with their approach: they are testing the performance of today&#8217;s already optimized sites!  There&#8217;s nothing in the middle of testing today&#8217;s sites and the more unrealistic &#8220;test every feature&#8221; ACID tests.</p>
<p>I believe more accurate tests for tomorrow would be useful, testing what&#8217;s pushing the limits of the web today, but are not currently top 100 sites.  My main objection with comparing performance across the top 100 web sites is this: <strong>The top 100 web sites are already relatively highly performant, because they are optimized for what&#8217;s possible today</strong>.  They have and continue to improve thanks in large part to the work of Steve Souders and others in the performance optimization community.  Because it costs significant amounts of money in server operations fees and bandwidth, high traffic web sites generally dedicate considerable resources to highly optimizing their sites. High traffic web sites also face significant competition and are highly scrutinized for acceptable page load time.  Budget and competition result in popular sites not deploying code that makes pages load slower than their desired performance threshold.  Even more importantly, top 100 sites have the budget to make their app work <strong>in the future</strong> when things change.  You can dedicate people on your team to squeezing out performance improvements in all aspects if you have the budget for it.  Most web apps cannot afford to do this.</p>
<p>When we&#8217;re testing the performance of new browsers or analyzing page load performance, we should also really be looking at what the top 100 sites will look like in terms of features and expectations in five years!  So how do we do that today?  There&#8217;s no simple answer, but here are some ideas:</p>
<ul>
<li>Test popular web apps, e.g. mint.com populated with large amounts of data</li>
<li>Test apps that don&#8217;t support IE6, e.g. Google Wave</li>
<li>Test all sections of popular sites, not just the home page, through an automated performance test harness</li>
<li>Test ridiculous configurations of popular applications, e.g. enable every feature in modular applications until they slow down</li>
<li>Test apps over long amounts of time in the browser, not just initial page load time</li>
<li>Test 50 apps, each in a different tab, all at once, and see how fast you can make a browser like Firefox or IE crash!</li>
<li>Test throttled networks that emulate the profile of mobile and satellite networks, slow hotel wi-fi networks that often limit the length and duration of connections, corporate proxies, tech conferences, and countries with overloaded pipes (e.g. YouTube in New Zealand)</li>
</ul>
<p>Only when browsers are pushed to their limits do we see where they break down, and how sites break them.  We also need tests and tools (such as instrumented usage of YSlow, PageSpeed, SpeedTracer, etc.) comparing the most complex apps and how they perform across the various browsers, as today&#8217;s complex app is potentially tomorrow&#8217;s median site.</p>
<p>To be clear, I&#8217;m not saying &#8220;don&#8217;t optimize for today&#8221;. I&#8217;m saying, stop comparing cutting edge sites to Google search results.  Lumping these two together in a common test is like putting apples against oranges because they are both round fruit.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/06/09/string-performance-getting-good-performance-from-internet-explorer/' rel='bookmark' title='Permanent Link: String Performance: Getting Good Performance from Internet Explorer'>String Performance: Getting Good Performance from Internet Explorer</a></li><li><a href='http://www.sitepen.com/blog/2008/03/24/why-apple-is-investing-in-webkit-performance/' rel='bookmark' title='Permanent Link: Why Apple is Investing in WebKit Performance'>Why Apple is Investing in WebKit Performance</a></li><li><a href='http://www.sitepen.com/blog/2009/08/10/web-page-global-variable-performance/' rel='bookmark' title='Permanent Link: Web Page Global Variable Performance'>Web Page Global Variable Performance</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2010/01/11/performance-testing-of-the-top-100-sites-is-misleading-at-best/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dojo 1.4 Released!</title>
		<link>http://www.sitepen.com/blog/2009/12/10/dojo-1-4-released/</link>
		<comments>http://www.sitepen.com/blog/2009/12/10/dojo-1-4-released/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:08:27 +0000</pubDate>
		<dc:creator>Dylan</dc:creator>
				<category><![CDATA[Dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Vector Graphics]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=878</guid>
		<description><![CDATA[Dojo 1.4 is hot off the presses, with more than seven months of significant improvements to performance, stability, and features.
Of particular interest:

IO Pipeline topics
dojo.cache
dojo.contentHandlers
dojo.hash with native HTML5 onhashchange event support where available
Traversal and manipulation for NodeLists (the return value for dojo.query)
dojo.ready (easier to type than dojo.addOnLoad)
Hundreds of refinements to the Dijit API and collection of [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/08/20/dojo-09-released/' rel='bookmark' title='Permanent Link: Dojo 0.9 released'>Dojo 0.9 released</a></li><li><a href='http://www.sitepen.com/blog/2008/03/28/introducing-the-dojo-toolkit-11/' rel='bookmark' title='Permanent Link: Introducing the Dojo Toolkit 1.1'>Introducing the Dojo Toolkit 1.1</a></li><li><a href='http://www.sitepen.com/blog/2007/10/13/dojo-grid-update/' rel='bookmark' title='Permanent Link: Dojo Grid Update'>Dojo Grid Update</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Dojo 1.4 is hot off the presses, with more than seven months of <a href="http://docs.dojocampus.org/releasenotes/1.4">significant improvements to performance, stability, and features</a>.</p>
<p>Of particular interest:</p>
<ul>
<li>IO Pipeline topics</li>
<li>dojo.cache</li>
<li>dojo.contentHandlers</li>
<li>dojo.hash with native HTML5 onhashchange event support where available</li>
<li>Traversal and manipulation for NodeLists (the return value for dojo.query)</li>
<li>dojo.ready (easier to type than dojo.addOnLoad)</li>
<li>Hundreds of refinements to the Dijit API and collection of Dijits, and a few new widgets in DojoX</li>
<li>DataChart widget and other improvements to charting</li>
<li>dojox.drawing lands!</li>
<li>Editor improvements and new plug-ins in both Dijit and DojoX</li>
<li>Grid is faster, and the EnhancedGrid lands!</li>
<li>ForestStoreModel for the TreeGrid</li>
<li>GFX improvements</li>
<li>dojox.jq, a very experimental module aimed at trying to match the jQuery API as close as possible, but using Dojo underneath</li>
<li>Dojo build system optionally supports the Google Closure Tools compiler</li>
<li>Significant speed improvements, especially in IE</li>
</ul>
<p>Read the full <a href="http://docs.dojocampus.org/releasenotes/1.4">Dojo 1.4 release notes</a> for more details!  And thanks to everyone in the Dojo community that helped make this release great!</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/08/20/dojo-09-released/' rel='bookmark' title='Permanent Link: Dojo 0.9 released'>Dojo 0.9 released</a></li><li><a href='http://www.sitepen.com/blog/2008/03/28/introducing-the-dojo-toolkit-11/' rel='bookmark' title='Permanent Link: Introducing the Dojo Toolkit 1.1'>Introducing the Dojo Toolkit 1.1</a></li><li><a href='http://www.sitepen.com/blog/2007/10/13/dojo-grid-update/' rel='bookmark' title='Permanent Link: Dojo Grid Update'>Dojo Grid Update</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2009/12/10/dojo-1-4-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Convergence of Chrome OS and Android?</title>
		<link>http://www.sitepen.com/blog/2009/12/08/convergence-of-chrome-os-and-android/</link>
		<comments>http://www.sitepen.com/blog/2009/12/08/convergence-of-chrome-os-and-android/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:59:22 +0000</pubDate>
		<dc:creator>Dylan</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=864</guid>
		<description><![CDATA[Google recently was asked about something we have suspected: Android and Chrome OS may converge.  From our perspective, Android and Chrome OS both offer compelling opportunities for building great web apps, but having two distinct operating systems from Google, each with different approaches to development, just adds complexity and confusion to the overall development [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/11/12/an-android-without-gears/' rel='bookmark' title='Permanent Link: An Android without Gears?'>An Android without Gears?</a></li><li><a href='http://www.sitepen.com/blog/2009/09/22/why-we-love-chrome-frame/' rel='bookmark' title='Permanent Link: Why We Love Chrome Frame'>Why We Love Chrome Frame</a></li><li><a href='http://www.sitepen.com/blog/2008/04/23/sdk-showdown-iphone-vs-android/' rel='bookmark' title='Permanent Link: SDK showdown: iPhone vs. Android'>SDK showdown: iPhone vs. Android</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>Google recently was asked about something we have suspected: <a href="http://www.pcworld.com/businesscenter/article/182784/brin_two_google_operating_systems_may_become_one.html">Android and Chrome OS may converge</a>.  From our perspective, Android and Chrome OS both offer compelling opportunities for building great web apps, but having two distinct operating systems from Google, each with different approaches to development, just adds complexity and confusion to the overall development landscape.  Of course, it still bothers us that iPhone apps and Dashboard widgets aren&#8217;t interoperable.</p>
<p>Android has the first mover advantage of being deployed today to many devices, but to really get the most out of it, you really should develop using Java, or employ a toolkit like PhoneGap.  Chrome OS offers the promise of using web technologies that are popular today, but is not yet production-ready, or optimized for mobile devices like <a href="http://developer.palm.com/">Palm&#8217;s webOS</a>.</p>
<p>The long-term expected convergence from Google makes sense.  Convergence of Palm&#8217;s webOS with Chrome OS makes sense to us as well as they are both pushing towards having a very similar WebKit-based operating system for delivering web applications.  Palm already appears to be moving in the direction of converging with Chrome through their adoption of key technologies in webOS such as Google&#8217;s V8 JavaScript engine. There&#8217;s nothing confirming that this will happen, other than it just making sense.</p>
<p>While there is a lot of short term interest in apps, you can still get significant results from mobile web apps, and the gap between a native app and a web-based app will quickly shrink, as <a href="http://theappleblog.com/2009/11/26/pie-guy-web-apps-as-viable-alternatives/">evidenced by apps like Pie Guy</a>.  After all, web apps don&#8217;t require app store approval!</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/11/12/an-android-without-gears/' rel='bookmark' title='Permanent Link: An Android without Gears?'>An Android without Gears?</a></li><li><a href='http://www.sitepen.com/blog/2009/09/22/why-we-love-chrome-frame/' rel='bookmark' title='Permanent Link: Why We Love Chrome Frame'>Why We Love Chrome Frame</a></li><li><a href='http://www.sitepen.com/blog/2008/04/23/sdk-showdown-iphone-vs-android/' rel='bookmark' title='Permanent Link: SDK showdown: iPhone vs. Android'>SDK showdown: iPhone vs. Android</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2009/12/08/convergence-of-chrome-os-and-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gears is Dead?  Long live Gears!</title>
		<link>http://www.sitepen.com/blog/2009/12/08/gears-is-dead-long-live-gears/</link>
		<comments>http://www.sitepen.com/blog/2009/12/08/gears-is-dead-long-live-gears/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:57:43 +0000</pubDate>
		<dc:creator>Dylan</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[browsers]]></category>
		<category><![CDATA[offline]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=869</guid>
		<description><![CDATA[It was recently reported that Google Dumps Gears for HTML5.  If true, with the investment Google has made in HTML5, Chrome, Chrome OS, and Chrome Frame, this is not surprising, but it does leave a potential short-term gap for offline application development.
In their post, Read-Write Web asks if offline access is even necessary any [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/05/30/google-gears-dojo-offline-and-sitepen/' rel='bookmark' title='Permanent Link: Google Gears, Dojo Offline, and SitePen'>Google Gears, Dojo Offline, and SitePen</a></li><li><a href='http://www.sitepen.com/blog/2009/09/22/why-we-love-chrome-frame/' rel='bookmark' title='Permanent Link: Why We Love Chrome Frame'>Why We Love Chrome Frame</a></li><li><a href='http://www.sitepen.com/blog/2007/11/12/an-android-without-gears/' rel='bookmark' title='Permanent Link: An Android without Gears?'>An Android without Gears?</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>It was recently reported that <a href="http://www.readwriteweb.com/archives/google_dumps_gears_for_html5.php">Google Dumps Gears for HTML5</a>.  If true, with the investment Google has made in HTML5, Chrome, Chrome OS, and Chrome Frame, this is not surprising, but it does leave a potential short-term gap for offline application development.</p>
<p>In their post, Read-Write Web asks if offline access is even necessary any longer.  I guess they don&#8217;t spend enough time on airplanes or at hotels and conferences with poor internet connectivity!  It&#8217;s certainly necessary, and while other browsers have developed significant offline capabilities, older browsers still need a plug-in like Gears.</p>
<p>In the interim, what should you do if you want an offline application?  Do you develop for Gears and HTML 5 features?  Do you wait for Chrome Frame to integrate offline capabilities?  Do you use a toolkit like Dojo which will wrap the various possibilities?  Or do you rely on something else like AIR, Titanium, Prism, or Fluid?  The answer really depends on your application.  If it is live now, you plan for the future but you keep going with Gears and/or Dojo Offline.  If you won&#8217;t be launching for some time, you may want to <a href="https://www.sitepen.com/contact/">talk to us about your offline app options</a>.</p>
<p>At the end of the day, Gears is open source.  If there&#8217;s a long-term need for its existence, the community can pick it up and run with it!  Thankfully end-of-life isn&#8217;t the certain death-knell that it is with closed-source software.</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2007/05/30/google-gears-dojo-offline-and-sitepen/' rel='bookmark' title='Permanent Link: Google Gears, Dojo Offline, and SitePen'>Google Gears, Dojo Offline, and SitePen</a></li><li><a href='http://www.sitepen.com/blog/2009/09/22/why-we-love-chrome-frame/' rel='bookmark' title='Permanent Link: Why We Love Chrome Frame'>Why We Love Chrome Frame</a></li><li><a href='http://www.sitepen.com/blog/2007/11/12/an-android-without-gears/' rel='bookmark' title='Permanent Link: An Android without Gears?'>An Android without Gears?</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2009/12/08/gears-is-dead-long-live-gears/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Persevere 1.0</title>
		<link>http://www.sitepen.com/blog/2009/11/13/persevere-1-0/</link>
		<comments>http://www.sitepen.com/blog/2009/11/13/persevere-1-0/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 19:11:49 +0000</pubDate>
		<dc:creator>Kris Zyp</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Persevere]]></category>

		<guid isPermaLink="false">http://www.sitepen.com/blog/?p=759</guid>
		<description><![CDATA[Persevere 1.0 is now available for  download. Persevere is a JavaScript storage and application server that uses a standards-based interface of HTTP/REST, JSON-RPC, JSONPath, and REST Channels. Persevere is designed for rich client applications and can be used with any framework or client. The Persevere Server runs on Rhino and provides persistent data storage [...]


Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/11/18/when-to-use-persevere-a-comparison-with-couchdb-and-others/' rel='bookmark' title='Permanent Link: When to Use Persevere: a Comparison with CouchDB and Others'>When to Use Persevere: a Comparison with CouchDB and Others</a></li><li><a href='http://www.sitepen.com/blog/2008/05/13/the-latest-from-sitepen-labs/' rel='bookmark' title='Permanent Link: The Latest from SitePen Labs'>The Latest from SitePen Labs</a></li><li><a href='http://www.sitepen.com/blog/2008/11/02/using-the-persistent-object-model-in-persevere/' rel='bookmark' title='Permanent Link: Using the Persistent Object Model in Persevere'>Using the Persistent Object Model in Persevere</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.persvr.org/">Persevere</a> 1.0 is now available for <a href="http://code.google.com/p/persevere-framework/downloads/list" target="_blank"> download</a>. Persevere is a JavaScript storage and application server that uses a standards-based interface of HTTP/REST, JSON-RPC, JSONPath, and REST Channels. Persevere is designed for rich client applications and can be used with any framework or client. The Persevere Server runs on Rhino and provides persistent data storage of dynamic JSON data in an interactive server side JavaScript environment with the following key features:</p>
<ul>
<li>Create, read, update, and delete access to persistent data through a standard <a href="http://www.json.org/">JSON</a> <a href="http://www.ietf.org/rfc/rfc2616.txt">HTTP/REST</a> web interface</li>
<li>Dynamic object persistence &#8211; expando objects, arrays, and JavaScript functions can be stored, for extensive JavaScript persistence support
<li>Remote execution of JavaScript methods on the server through <a href="http://json-rpc.org">JSON-RPC</a> for a consistent client/server language platform</li>
<li>Flexible and fast indexed query capability through <a href="http://www.sitepen.com/blog/2008/07/16/jsonquery-data-querying-beyond-jsonpath/">JSONQuery</a>/<a href="http://goessner.net/articles/JsonPath/">JSONPath</a></li>
<li><a href="http://www.sitepen.com/technology/">Comet</a>-based data monitoring capabilities through HTTP Channels with <a href="http://www.sitepen.com/labs/cometd.php">Bayeux</a> transport plugin/negotiation support</li>
<li>Data-centric role-based object level security with user management, Persevere is designed to be accessed securely through Ajax with public-facing sites</li>
<li>Comprehensive referencing capabilities using <a href="http://www.json.com/2007/10/19/json-referencing-proposal-and-library/">JSON referencing</a>, including circular, multiple, lazy, non-lazy, cross-data source, and cross-site referencing for a wide variety of object structures</li>
<li>Data integrity and validation through <a href="http://groups.google.com/group/json-schema">JSON Schema</a> based definitions</li>
<li><a href="http://persevere.sitepen.com/#structure">Class-based data hierarchy</a> &#8211; typed objects can have methods, inheritance, class-based querying</li>
<li>Pluggable data source architectures &#8211; SQL tables, XML files, remote web services can be used as data stores</li>
<li>Object versioning with transactional history of record states</li>
</ul>
<h2>Persevere in use</h2>
<p>Recently, Cramer Development put together a <a href="http://websticki.es/">slick little application</a> for making sticky notes. They <a href="http://cramerdev.com/weblog/the-making-of-stickies">discuss</a> how quickly the application came together, as Persevere allowed them to quickly establish a data API, and then focus on the client side interface.</p>
<p>Other users include:</p>
<ul>
<li><a href="http://www.dscs.com/">DataStream Content Solutions</a> is using Persevere to build an XML repository for legal data in combination with MarkLogic.
</li>
<li><a href="http://www.montana.edu/">Montana State University</a> is using Persevere for their <a href="http://yogo.msu.montana.edu/">Yogo Data Management Project</a>.</li>
<li>Another multi-national company is using Persevere in production for Intranet applications, with consistent usage from a number of users.</li>
<li>And, of course, we at SitePen are using Persevere for a number of the applications we are developing.</li>
</ul>
<p>Numerous others are using Persevere in a variety of ways.</p>
<h2>Learning more</h2>
<p>There are a number of resources for learning more about Persevere and getting started with it.</p>
<ul>
<li><a href="http://docs.persvr.org/">Persevere Documentation</a></li>
<li><a href="http://code.google.com/p/persevere-framework/" target="_blank">Download Persevere</a></li>
<li><a href="/support">SitePen Persevere Support</a></li>
<li><a href="http://www.sitepen.com/blog/category/persevere/">SitePen Persevere Blog</a></li>
<li><a href="http://www.sitepen.com/blog/2008/07/23/getting-started-with-persevere-using-dojo/">Getting Started with Persevere Using Dojo</a></li>
<li><a href="http://groups.google.com/group/persevere-framework" _blank="">Persevere Mailing List</a></li>
<li><a href="http://www.persvr.org/examples/customer.html" target="_blank">Persevere + Dojo (using Comet) demonstration</a></li>
</ul>
<h2>What&#8217;s Next</h2>
<p>With Persevere 1.0 finished, we are already working on the next version which will be based on the new <a href="http://github.com/kriszyp/pintura">Pintura</a> architecture. Pintura is the new JavaScript core for the Persevere HTTP interface that is based on the CommonJS and JSGI API. Pintura will run on any CommonJS/JSGI capable JavaScript engine (support for V8, JSCore, and Spidermonkey coming).</p>


<p>Related posts:<ol><li><a href='http://www.sitepen.com/blog/2008/11/18/when-to-use-persevere-a-comparison-with-couchdb-and-others/' rel='bookmark' title='Permanent Link: When to Use Persevere: a Comparison with CouchDB and Others'>When to Use Persevere: a Comparison with CouchDB and Others</a></li><li><a href='http://www.sitepen.com/blog/2008/05/13/the-latest-from-sitepen-labs/' rel='bookmark' title='Permanent Link: The Latest from SitePen Labs'>The Latest from SitePen Labs</a></li><li><a href='http://www.sitepen.com/blog/2008/11/02/using-the-persistent-object-model-in-persevere/' rel='bookmark' title='Permanent Link: Using the Persistent Object Model in Persevere'>Using the Persistent Object Model in Persevere</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.sitepen.com/blog/2009/11/13/persevere-1-0/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
