72 CHAPTER 3 CONTENT CHUNKING PATTERN (Web hosting india) It

72 CHAPTER 3 CONTENT CHUNKING PATTERN It seems a bit odd to download and assign links that are then processed by the web browser. This indirect approach is done not to illustrate how complicated a web application can be made. The indirect technique is necessary because directly downloading binary data is not possible. But all is not lost, because of the way that the browser caches images. If an image is referenced and downloaded, the image stays in the browser s cache. If the image is referenced a second time, the image is retrieved from the cache. Of course this happens only if the HTTP server implements caching. There is a downside: If a request is made for a URL that references an image, two HTTP requests are required: one to download the content that contains the URL of the image, and the image itself. If both requests are using HTTP 1.1, which most likely is the case, the requests will be inlined using a single connection. Another variation of the illustrated strategy is to download not a URL but the entire HTML to create an image. The strategy does not save a request connection, but provides a self-contained solution that involves no additional scripting. The following HTML code snippet illustrates how the entire img HTML tag is downloaded: When injecting both the imgtag and its appropriate srcattribute, the browser will dynam ically load the image as illustrated in the previous example. The advantage of injecting the HTML is that the server side could inject multiple images or other types of HTML. Additionally, by injecting the entire imgtag, there is no preliminary stage where a broken image is generated. However, either approach is acceptable, and which is used depends on the nature of the appli cation. When injecting HTML, there might be a flicker as the HTML page resizes. When you E B V assign the srcproperty, there is no flicker, but an empty image needs to be defined or the image element needs to be hidden. JavaScript Chunking Another form of chunking is the sending of JavaScript. Sending JavaScript can be very effective because you don t need to parse the data but only execute the JavaScript. From a client script point of view it is very easy to implement. For reference purposes, do not consider downloading JavaScript faster than manually parsing and processing XML data and then converting the data into JavaScript instructions. JavaScript that is downloaded needs to be parsed and validated before being executed. The advantage of using the JavaScript approach is simplicity and effectiveness. It is simpler to execute a piece of JavaScript and then reference the properties and functions exposed by the resulting execution. Executing JavaScript Consider the following HTML code that will execute some arbitrary JavaScript: