Ajax

Ajax (also AJAX; /ˈæks/; an acronym for Asynchronous JavaScript and XML)[1] is a group of interrelated web development techniques used on the client-side to create asynchronous web applications. With Ajax, web applications can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. Data can be retrieved using the XMLHttpRequest object. Despite the name, the use of XML is not required (JSON is often used instead), and the requests do not need to be asynchronous.[2]

Ajax is not a single technology, but a group of technologies. HTML and CSS can be used in combination to mark up and style information. The DOM is accessed with JavaScript to dynamically display, and allow the user to interact with, the information presented. JavaScript and the XMLHttpRequest object provide a method for exchanging data asynchronously between browser and server to avoid full page reloads.

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents.[1] Objects in the DOM tree may be addressed and manipulated by using methods on the objects. The public interface of a DOM is specified in its application programming interface (API). The history of the Document Object Model is intertwined with the history of the “browser wars” of the late 1990s between Netscape Navigator and Microsoft Internet Explorer, as well as with that of JavaScript and JScript, the first scripting languages to be widely implemented in the layout engines of web browsers.

Dojo or jQuery, quick answer

  • JQuery if you are new to javascript/web programming and only want to jazz up your pages a little. Also, if your project is only a few months and/or only a few hundred lines, pick JQuery. It will get you there faster.
  • Dojo if you have a large project and can spend time on a very steep learning curve and want to be able to create and re-use widgets, data connections and whatnot.

This answer do not take into account the “fun factor”. If your aim is to have fun JQuery will give you a quick fix but Dojo will be more rewarding in the long run.

JSON

JSON (/ˈsɒn/ JAY-sawn, /ˈsən/ JAY-sun), or JavaScript Object Notation, is a text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for many languages.

The JSON format was originally specified by Douglas Crockford, and is described in RFC 4627. The official Internet media type for JSON is application/json. The JSON filename extension is .json.

The JSON format is often used for serializing and transmitting structured data over a network connection. It is used primarily to transmit data between a server and web application, serving as an alternative to XML.

JSON’s basic types are:

  • Number (double precision floating-point format in JavaScript, generally depends on implementation)
  • String (double-quoted Unicode, with backslash escaping)
  • Boolean (true or false)
  • Array (an ordered sequence of values, comma-separated and enclosed in square brackets; the values do not need to be of the same type)
  • Object (an unordered collection of key:value pairs with the ‘:’ character separating the key and the value, comma-separated and enclosed in curly braces; the keys must be strings and should be distinct from each other)
  • null (empty)

Non-significant white space may be added freely around the “structural characters” (i.e. brackets “{ } [ ]”, colons “:” and commas “,”).

The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, a number field for age, an object representing the person’s address and an array of phone number objects.

{
    "firstName": "John",
    "lastName": "Smith",
    "age": 25,
    "address": {
        "streetAddress": "21 2nd Street",
        "city": "New York",
        "state": "NY",
        "postalCode": 10021
    },
    "phoneNumbers": [
        {
            "type": "home",
            "number": "212 555-1234"
        },
        {
            "type": "fax",
            "number": "646 555-4567"
        }
    ]
}

One potential pitfall of the free-form nature of JSON comes from the ability to write numbers as either numeric literals or quoted strings. For example, ZIP Codes in the northeastern U.S. begin with zeroes (for example, 07728 for Freehold, New Jersey). If written with quotes by one programmer but not by another, the leading zero could be dropped when exchanged between systems, when searched for within the same system, or when printed. In addition, postal codes in the U.S. are numbers but other countries use letters as well. This is a type of problem that the use of a JSON Schema (see below) is intended to reduce.

Since JSON is almost a subset of JavaScript, it is possible, but not recommended,[7] to parse most JSON text into an object by invoking JavaScript’s eval() function. For example, if the above JSON data is contained within a JavaScript string variable contact, one could use it to create the JavaScript object p as follows:

 var p = eval("(" + contact + ")");

The contact variable must be wrapped in parentheses to avoid an ambiguity in JavaScript’s syntax.[8]

The recommended way, however, is to use a JSON parser. Unless a client absolutely trusts the source of the text, or must parse and accept text that is not strictly JSON-compliant, one should avoid eval(). A correctly implemented JSON parser accepts only valid JSON, preventing potentially malicious code from being executed inadvertently.

 var p = JSON.parse(contact);

Browsers, such as Firefox 4 and Internet Explorer 8, include special features for parsing JSON. As native browser support is more efficient and secure than eval(), native JSON support is included in the recently-released Edition 5 of the ECMAScript standard.[9]

jQuery library wrap JSON object in function constructor and execute it immediately if JSON.parse is not present. This avoid using eval in the code.

 var p = new Function('return ' + contact ';')();

Despite the widespread belief that JSON is a JavaScript subset, this is not the case. Specifically, JSON allows the Unicode line terminators U+2028 line separator and U+2029 paragraph separator to appear unescaped in quoted strings, while JavaScript does not.[10] This is a consequence of JSON disallowing only “control characters”. This subtlety is important when generating JSONP.

Optimización de sitios de Internet

Para hablar de optimización es necesario primero definir el criterio de optimalidad.  En el caso de sitios de Internet el criterio es trafico y el logro de objetivos específicos.

Un aspecto primordial para la generación de trafico es la colocación del sitio es los buscadores; sin embargo, el logro de objetivos depende de la experiencia del usuario una vez que llega a la pagina: que el usuario encuentre fácilmente lo que esta buscando; que los objetivos del usuario se correlacionen con los objetivos del sitio; que la pagina se cargue dentro de los tiempos  tolerados por el usuario.

Algunos lineamientos generales en los que coinciden los expertos:

  • Mantener el diseño de paginas y del sitio en general lo más simple posible.
  • Evitar el uso de Flash e imágenes para presentar información.
  • Usar paginas estáticas en la medida de lo posible en vez de contenido dinámico.
  • Mantener la navegación del sitio lo más plano posible, con no más de tres niveles.
  • Enfocar el contenido a temas muy concretos y presentar información relevante y única.
  • Conseguir ligas de sitios importantes y relevantes con respecto a la temática del sitio.

En términos técnicos los recomendaciones implican,  por ejemplo, el uso de CSS para lograr efectos, CSS Sprites, datos embebidos.

Referencias