Category: "Ajax/JSON"

AJAX Page Load Improvement

The application I am working on has several very complex pages, which take some time to render in the browers. I used the link above to create a ‘loading‘ gif (with great thanks to the authors and contributors). Set up a div to contain the image and ‘Loading, please wait …‘ text, with z-index set to -1. Added dojo.OnLoad() to hide the loading div and display the main div.

The effect of these changes is to prevent display of the page content until dojo had fully rendered it.

A side effect is that the page seems to load and display much more quickly. I suspect this is because the browser doesn’t have to display the page as it is being rendered.

dojo - Smarty - PHP - Synchronizing client- and server-side validation

The following architecture with Smarty and dojo allows you to the client and server synchronized for validation for RIA/PHP applications.

Each input has 4 characteristics defined in a (PHP) .ini file -

V_input_name = regExp (usually includes length)
L_input_name = max length
R_input_name = true or false (required or not)
T_input_name = type of input data in database, used to support documentation



Each input also has 3 characteristics defined in a Smarty .conf file, and there is a .conf file for every language (.ini be under languages)

E_input_name = error message
I_input_name = invalid message
P_input_name = prompt message

Smarty constructs the input tags like so:

<input type="text" dojoType="dijit.form.ValidationTextBox"
    name="input_name" id="input_name"
    regExp="{#V_input_name#}"   
    errorMessage="{#E_input_name#}"
    promptMessage="{#P_input_name#}"
    invalidMessage="{#I_input_name#}"
    length="{#L_input_name#}" />



There is a simple javascript validation that accepts an array of inputs and tests if they are valid with input_name.isValid(), displaying input_name.errorMessage if not, and cancelling the submit.

On the server side, there is a loop that tests the inputs against the same strings:

foreach ($aInput as $k => $v)
  if (isset($aIni['V_'.$k]))
  { 
    $sInput=trim($v); 
    if (isset($aIni['R_'.$k])
    if (($aIni['R_'.$k]=='true') && ($sInput=='')) /* Test for required */
      return false;
    if (!filter($aIni['V_'.$k],$v))  /* flter ensures data complies with regexp */
        return false;
   }



This allows the client-side code to help the user enter valid data, and allows the server-side code to protect the server by disallowing or discarding data that isn’t valid.

Please note that page-level validation, where the required state and content of data may vary based on other inputs must be reflected at both the client and server side.

PHP 5.1 JSON

If you need the JSON support functions json_encode and json_decode, but your server is not running PHP 5.2+, consider using the Zend framework.

One of the nicest things about the JSON support is that it will use json_encode and json_decode if they are available, if not, it will handle it.

Zend framework can be used as a library, so if all you need is the JSON support, you won’t incur alot of overhead.

The new version of Zend Framework includes dojo!

Extend the capacity of a web server with careful common component management

Many web companies use a common, core set of javascript libraries and applications which use hierarchical CSS architectures.

If the live server is used for development (which is a very cost-effective approach), thousands of requests are made for the same files.

To reduce this, common components can be sourced from a single point, which the HTTP headers set to cache them with far-future expire dates.

In addition to reducing bandwidth consumption during the development phase, it also reduces it for live sites.

If there are related sites on the same server - the benefit is extended.

This is a small CDN (content delivery network), which allows distribution of customized files for a company, or custom code. It also simplifies management of the common code core, since updates only have to be made to one file.

This saves disk space as well, and speeds page loads.

If there is an issue with having content from a different URL, rewrite rules can be used to hide the true source of the files, while retaining the advantages of a single source.

With additional creative configuration, an application can be used to support multiple accounts. This is riskier, and I don’t recommend it - unless you can be sure you will never change the application. I would try it with this blog software (b2evolution), because from what I’ve seen - it would be very successful.

Web n.0

I think the near future of the web will focus more heavily on the technology than the functionality of sites.

Two areas will be extremely important, performance - meaning AJAX, and security.