29.11.2012 Views

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

developer to figure out what works best for a particular<br />

applicati<strong>on</strong>.<br />

This kind of approach to building web applicati<strong>on</strong>s<br />

also easily results in tightly coupled systems. Not <strong>on</strong>ly<br />

do the server and the client become dependent <strong>on</strong> each<br />

other but there is also coupling between different comp<strong>on</strong>ents<br />

or technologies within the applicati<strong>on</strong>. For example,<br />

the server usually sends a complete HTML page<br />

to the browser but <strong>on</strong> some occasi<strong>on</strong>s it may <strong>on</strong>ly send<br />

parts of the page and rely <strong>on</strong> the client side JavaScript to<br />

fetch the rest of the data (e.g. XML) using Ajax requests.<br />

Also the applicati<strong>on</strong> flow has to be agreed in advance between<br />

the client and the server. As a result it would be<br />

very difficult to implement a completely different kind<br />

of user interface for the applicati<strong>on</strong> without making any<br />

changes to server side comp<strong>on</strong>ents.<br />

2.3 Burden of Running <strong>Web</strong> Applicati<strong>on</strong>s<br />

By its very nature, HTTP is a stateless protocol. Therefore,<br />

each request occurs in complete isolati<strong>on</strong> from any<br />

other request. When user clicks <strong>on</strong> a link <strong>on</strong> a web page<br />

and another page within the same applicati<strong>on</strong> is presented,<br />

the browser has to load that new page completely<br />

from the server and forget everything it knew about the<br />

previous page. Thus, from the client’s perspective the<br />

applicati<strong>on</strong> is restarted each time a page is loaded. However,<br />

many applicati<strong>on</strong>s require their internal state to be<br />

maintained while the user is running the applicati<strong>on</strong> and<br />

new pages are loaded. That is why the client side of the<br />

applicati<strong>on</strong> depends <strong>on</strong> the server to maintain the applicati<strong>on</strong><br />

state between page loads.<br />

This kind of behavior is usually implemented as a<br />

server side sessi<strong>on</strong>. Each time the browser sends an<br />

HTTP request, it sends a cookie with the request. Within<br />

the cookie there is a unique identifier that identifies the<br />

client’s sessi<strong>on</strong> and the server then has to interpret all<br />

the data in the sessi<strong>on</strong> to see where – in the flow of the<br />

applicati<strong>on</strong> – the client was. Now the server can resume<br />

the applicati<strong>on</strong> state and c<strong>on</strong>tinue into processing the request.<br />

In the following, we list comm<strong>on</strong> steps that the<br />

server has to take when a page is requested:<br />

1. Resume the applicati<strong>on</strong> state by processing the received<br />

cookie and recovering the associated sessi<strong>on</strong>.<br />

2. Invoke appropriate c<strong>on</strong>troller functi<strong>on</strong> to execute<br />

the applicati<strong>on</strong> logic.<br />

3. Use the model to retrive and update associated persistent<br />

data.<br />

4. Locate correct view and populate it with the data<br />

from the model.<br />

5. Update the sessi<strong>on</strong> to reflect the new state of the<br />

client’s applicati<strong>on</strong>.<br />

6. Return the populated HTML page to the browser.<br />

It should be noted, that we have purposefully left out<br />

things that are not relevant in the scope of this paper.<br />

When the browser receives the newly composed<br />

HTML page it has to parse and render it <strong>on</strong> the screen.<br />

This includes fetching all the related resources that the<br />

page uses, in essence, CSS, JavaScript and image files.<br />

While some of these resources may come from the<br />

cache, some of them do not. This laborious sequence of<br />

events takes place every time the user performs a functi<strong>on</strong><br />

that requires a new page to be loaded. There has<br />

been a lot of research <strong>on</strong> how to make web sites faster<br />

([16, 17]) and there are dozens of tricks that developers<br />

need to know and implement in order to minimize the<br />

overhead and latency during page loading.<br />

3 The Partiti<strong>on</strong>ed Way of Building <strong>Web</strong><br />

Applicati<strong>on</strong>s<br />

Given the complexity of building, running and maintaining<br />

web applicati<strong>on</strong>s with a lot of functi<strong>on</strong>ality we argue<br />

that these applicati<strong>on</strong>s should be implemented in a simpler<br />

way. This simplicity can be achieved by breaking<br />

the applicati<strong>on</strong> in parts and strictly defining their resp<strong>on</strong>sibilities.<br />

In the following secti<strong>on</strong>s we describe this process<br />

in more detail.<br />

3.1 Breaking the Applicati<strong>on</strong> in Two<br />

Based <strong>on</strong> the fact that the web builds <strong>on</strong> top of HTTP, applicati<strong>on</strong>s<br />

using it as their platform are distributed over<br />

the network. Furthermore, as HTTP is a resource oriented<br />

and stateless protocol, we argue that web applicati<strong>on</strong>s<br />

should be broken into services provided by the<br />

server and the client that uses these services to compose<br />

a meaningful web applicati<strong>on</strong>. From this separati<strong>on</strong><br />

we draw the following set of rules that web applicati<strong>on</strong>s<br />

should adhere to:<br />

1. Applicati<strong>on</strong> state is stored in the applicati<strong>on</strong>, not in<br />

the server.<br />

2. Client applicati<strong>on</strong> is a self c<strong>on</strong>tained entity built <strong>on</strong><br />

top of services provided by single or multiple sites.<br />

3. Services that are used for implementing the applicati<strong>on</strong><br />

do not make any assumpti<strong>on</strong>s about the<br />

clients using them.<br />

The motivati<strong>on</strong> and c<strong>on</strong>sequences of the rules are the<br />

following:<br />

1) As already menti<strong>on</strong>ed, from the client’s perspective<br />

the applicati<strong>on</strong> is restarted each time a new page is<br />

loaded. Effectively this means that either the applicati<strong>on</strong><br />

should be implemented as a so called single page web<br />

applicati<strong>on</strong> or it explicitly stores its state using services<br />

provided by the server.<br />

2) Making the client applicati<strong>on</strong> a self c<strong>on</strong>tained entity<br />

makes the resp<strong>on</strong>sibilities explicit and unambiguous:<br />

the server decides which services it exposes and<br />

<str<strong>on</strong>g>USENIX</str<strong>on</strong>g> Associati<strong>on</strong> <strong>Web</strong>Apps ’11: <str<strong>on</strong>g>2nd</str<strong>on</strong>g> <str<strong>on</strong>g>USENIX</str<strong>on</strong>g> <str<strong>on</strong>g>C<strong>on</strong>ference</str<strong>on</strong>g> <strong>on</strong> <strong>Web</strong> Applicati<strong>on</strong> <strong>Development</strong> 89

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!