Thursday, September 29th, 2005
This should be filed under the quirky category :)
Julien Lamarre has demonstrated doing Ajax-style callbacks not using XHR. Nor iframes. Nor Java. Nor Flash.
He implemented it with images and CSS.
- The client to server connection works by sending a request to the server using a dynamically created image with some parameters added to its “.src” property.
The server’s response is sent in a cookie at the same time the generated image is returned to the client. Or, when cookies are disabled, by using the image’s width and height to send, two by two, the characters forming the response!
- There are some limitations and performance issues related to this technique, especially when cookies are disabled on the client.
- A lot of improvements could be done. In the cookie version for example, an iteration method that would split the server’s response and send it chunk by chunk would be a good idea to deal with a cookie’s size limit.
- The associated PHP file: image.php
- This technique will only work if your browser supports [an element].currentStyle() or window.getComputedStyle(). This means it won’t work with old browsers.
- The client to server connection works by making a stylesheet’s “.href” property point to the PHP file, followed by the request’s parameters.
The server’s response is done by generating a stylesheet that includes the response inside the “background-image” property of an hidden div.
- This technique’s main limitation is the number of characters that can be used for a “background-image” property’s value. An iteration method that would split the server’s response and send it chunk by chunk would be a good idea to deal with this.
There is also the fact that only recent browsers can be targeted.
- The associated PHP file: stylesheet.php
Posted by Dion Almaer at 12:39 am