Code on demand

In distributed computing, code on demand is any technology that sends executable software code from a server computer to a client computer upon request from the client's software. Some well-known examples of the code on demand paradigm on the web are Java applets, Adobe's ActionScript language for the Flash Player, and JavaScript.[1]

The program code lies inactive on a web server until a user (client) requests a web page that contains a link to the code using the client's web browser. Upon this request, the web page and the program are transported to the user's machine using HTTP. When the page is displayed, the code is started in the browser and executes locally, inside the user's computer until it is stopped (e.g., by the user leaving the web page).

Code on demand is a specific use of mobile code, within the field of code mobility.[2]



The first constraint is that the system must be made up of clients and servers.

Servers have resources that clients want to use. For example, a server has a list of stock prices (i.e. a resource) and the client would like to display these prices in some nice graphs.

There is a clear separation of concerns between the two. The server takes care of the back-end stuff (data storage, business rules, etc.) and the client handles the front-end stuff (user interfaces).


To further simplify interactions between clients and servers, the second constraint is that the communication between them must be stateless.

This means that all information about the client’s session is kept on the client, and the server is completely unaware. The consequence is that each request must contain all information necessary to perform the request (i.e. it cannot rely on any context information).


The last constraint on the client-server communication is that responses from servers must be marked as cacheable or non-cacheable.

An effective cache can reduce the number of client-server interactions, which contributes positively to the performance of the system. At least, from a user’s point of view.


Code-on-Demand (COD) is the only optional constraint in REST. It allows clients to improve its flexibility because, in fact, it is the server who decides how certain things will be done. For instance, with Code-On-Demand, a client can download a javascript, java applet or even a flash application in order to encrypt communication so servers are not aware of any encryption routines / keys used in this process.

However, using COD reduces visibility, which is why this constraint is optional. Also, not every API needs this kind of flexibility.

See alsoEdit


  1. ^ Carzaniga, Antonio; Gian Pietro Picco; Giovanni Vigna (2007). Is Code Still Moving Around? Looking Back at a Decade of Code Mobility. ICSE COMPANION '07 Companion to the Proceedings of the 29th International Conference on Software Engineering. Washington, DC, USA: IEEE Computer Society. pp. 9–20. CiteSeerX doi:10.1109/ICSECOMPANION.2007.44. ISBN 978-0-7695-2892-2.
  2. ^ Fuggetta, Alfonso; Gian Pietro Picco; Giovanni Vigna (1998). "Understanding Code Mobility". IEEE Transactions on Software Engineering. 24 (5): 342–361. CiteSeerX doi:10.1109/32.685258. ISSN 0098-5589. Retrieved 29 July 2009.