AJAX
  Home arrow AJAX arrow Page 4 - Uncompressing Source Files with Google`s AJAX Libraries API
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
AJAX

Uncompressing Source Files with Google`s AJAX Libraries API
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 12
    2009-01-20


    Table of Contents:
  • Uncompressing Source Files with Google`s AJAX Libraries API
  • Serving JavaScript files using compression
  • Serving JavaScript files without using compression
  • Assembling the modules of the Ajax application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Uncompressing Source Files with Google`s AJAX Libraries API - Assembling the modules of the Ajax application
    ( Page 4 of 4 )

    In case you wish to test how the previous Ajax application works, now that it downloads the Prototype dependencies without using compression, below I listed its entire source code, including the PHP file that fetches the contents from a text file and sends them back to the client:


    (definition for 'ajax_file_reader.htm' file)


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Reading file contents with Prototype library (uses Google API)</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    h1{

    font: bold 18pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    #filecontents{

    width: 600px;

    padding: 10px;

    border: 1px solid #999;

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    </style>

    <script src="http://www.google.com/jsapi"></script>

    <script>

    // load Prototype library with Google API (loads uncompressed source file)

    google.load("prototype", "1.4",{uncompressed:true});

    // read file contents with Ajax

    function readFileContents(){

    // send http request

    var ajaxobj=new Ajax.Request('read_file.php',{method: 'get',onComplete: displayFileContents,onFailure: displayError});

    }

    // display file contents

    function displayFileContents(requestObj){

    $('filecontents').innerHTML=requestObj.responseText;

    }

    // display error message

    function displayError(requestObj){

    $('filecontents').innerHTML='Error reading file contents!';

    }

    // initialize file reading application

    function initializeApplication(){

    // attach click handler to HTML button

    Event.observe('btn','click',readFileContents);

    }

    google.setOnLoadCallback(initializeApplication);

    </script>

    </head>

    <body>

    <h1>Reading File Contents with Prototype library (uses Google API)</h1>

    <p><input type="button" id="btn" value="Read File Now!" /></p>

    <div id="filecontents"></div>

    </body>

    </html>



    definition for 'read_file.php' file)


    <?php

    if(!$contents=file_get_contents('data.txt')){

    trigger_error('Error reading file contents',E_USER_ERROR);

    }

    echo $contents;

    ?>



    (definition for 'data.txt' file)


    These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file. These are contents of sample file.


    Now that you have at your disposal the complete source code of this sample Ajax application, feel free to play a bit with the “google.load()” method. Try running the program by using the compressed and uncompressed options, so you can evaluate more accurately how these options affect its overall performance.

    Final thoughts

    In this third chapter of the series, I explained how to serve, via the Google API, a specified JavaScript library without using compression. Indeed, this was not a difficult process at all, which implies that you shouldn’t have major problems grasping how it works.

    In the final part, I’ll be discussing how to use Google's Ajax Libraries API to serve the jQuery library without compressing its source file. Therefore, now that you’ve been warned about the subject of the last installment of the series, you can’t miss it!



     
     
    >>> More AJAX Articles          >>> More By Alejandro Gervasio
     

       

    AJAX ARTICLES

    - PHP AJAX Form Validation
    - Completing a User-Defined CSS Website with P...
    - Create a User-Defined CSS Website with PHP
    - Build A Better Twitter Chat Client Than Cham...
    - Using Division Equations to Make Web Forms S...
    - Using Integer Multiplication to Protect Web ...
    - Using Simple Checksums for Web Form Verifica...
    - Protecting Web Forms with AJAX
    - Using Prototip with AJAX
    - Using Prototip
    - Using the google.load() Method with Google`s...
    - How to Handle Ajax Errors
    - Uncompressing Source Files with Google`s AJA...
    - Using the jQuery Framework with Google`s Aja...
    - Using Google`s Ajax Libraries API




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek