Zen of Web development

Learn it, Live it, Love it.

Google VS PHP

leave a comment »

Here is the recent article Google published for Web optimisation technique for PHP. It got bad PHP community slap back especially from the Sitepoint.com and Google group forum. It is quiet interesting to see how beginner PHP will actually fall in the trap which recomemded so of the tips from the articles.

Written by Charles Ling

27 June, 2009 at 9:14 PM

Posted in PHP

Tagged with

JQuery get $.getJSON data

with one comment

Imagine you have server side data return to your Javascript client side.

   1:  var groupid = null;
   2:  
   3:  $.getJSON(url, data,
   4:      function(result){
   5:  
   6:       groupid = result.groupid;
   7:       //do whatehever you like here
   8:  
   9:      // you wanted to return the data that you have been parsed or assign
  10:      }
  11:  );
  12:  
  13:  alert(groupid ); //error : will return null

So instead of that, we need to use delegate or callback function that JQuery have provided to us. Remember the $.fn. thing.

Now let see how we can use the delegate function to return us the data:

   1:  $.getJSON(path + "?request=url.here",
   2:  function (data)
   3:  {
   4:     var selectOption = '';
   5:  
   6:     //do what ever you like with the json data
   7:     selectOption =  selectOption + "testing" + data; //example only
   8:     $.fn.delegateJSONResult(selectOption );
   9:  });
  10:  
  11:  $.fn.delegateJSONResult = function(data) {
  12:    alert(data);
  13:  }

Written by Charles Ling

27 June, 2009 at 6:42 PM

Posted in Javascript, jQuery

Tagged with ,

Javascript : A better way to check null object

leave a comment »

Here is one of the good way to check if the object is null or undefined.

   1:  if ( (typeof(object.table1)  !== "undefined") && object. != null ) {
   2:    //do something cool here
   3:  }

PHP var_dump in Javascript.

One way to get all the object data in Javascript object if you are not using Firefox add-on (Firebug) console.debug.

   1:  function var_dump(object) {
   2:
   3:  var output = "";
   4:
   5:  for (var key in object) {
   6:     output += key + " : " + object[key] + "\n";
   7:  }
   8:
   9:  alert(output);
  10:
  11:  }

Written by Charles Ling

24 June, 2009 at 11:59 AM

Posted in Javascript

Improve Response Time with Header Cache

leave a comment »

Recently i have been developing web application with Zend framework 1.8 (the latest release version). The latest version of Zend framework are much better in terms flexibility  of configuring the Boostrap file by extending Zend_Application_Bootstrap_Bootstrap. Personally, i used dimensional arrays style of config to set up in different  environments.

I have done some simple optimisation technique for the website response time by following the guidelines provide at YUI (Yahoo Developer Center). One of the problem  i faced, was the response time of Javascript and CSS file was to long. I use the function below in the bootstrap to cache both of the files and compression with the Accept-Encoding header in the HTTP request.

   1:  protected function _initResponse()
   2:  {
   3:     // Create a new HTTP response
   4:     $response = new Zend_Controller_Response_Http();
   5:  
   6:     // Set the response headers : the value below are only set for example.
   7:     $response->setHeader('language', 'en')
   8:              ->setHeader('content-language', 'en')
   9:              ->setHeader('Content-Type', 'text/html; charset=utf-8')
  10:              ->setHeader('Accept-Encoding', 'gzip, deflate')
  11:  
  12:              ->setHeader('Expires', 'max-age=7200, must-revalidate’, true)
  13:              ->setHeader('Cache-Control', 'public', true)
  14:              ->setHeader('Cache-Control', 'max-age=7200') //only for testing
  15:              ->setHeader('Pragma', '', true);
  16:  
  17:     // Assign the response to the front controller
  18:     $this->getPluginResource(’frontController’)->getFrontController()->setResponse($response);
  19:  }

Refer to this W3C documentation for the meaning of the attributes : http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

First Reload Result :

Firebug Net reload result

Second Reload Result :

Firebug Net Reload Result

Written by Charles Ling

11 May, 2009 at 4:11 PM

Posted in Technology, Zend

Tagged with ,

My Favourite Web Development tools.

with 6 comments

Every few months, i will be googling or check out new web development tools for my work and personal projects. Unbelievably,  new cool and fantastic tools kept poping up, something you even have problem which best tool to used. The tools i meant here, are tools like IDE, plug-in, library, framework, cms, test-suite and more. Below, are the list of tools that currently i am using and found it very useful and increasing my productivity. All the tools are OPEN  SOURCE which i am a very big fan of.

Firefox Add-ons

——————-

1.  Again, Firebug win my heart. This tool let you inspect and edit CSS on the fly. Not only css, debugging javascript with it, save tons of your time to look for javascript errors.

Firebug screen shot

Firebug screen shot

2. iOpus iMacros – from a Firefox add-ons : to record form filling and replay the task you had been recorded. Save your time kept repeating testing for web forms, useful for web testing, web scraping and more.

IMacro

IMacro

3. Web development- from a Firefox add-ons : Great tools with lots of functionality for web developers. Such as markup validation,  cookies management, http header management and more.

Web Development toolbar (Firefox add-ons)

Web Development toolbar (Firefox add-ons

4. XDebug for Javascript

5. Yahoo YSLOW – Javascript profiler : A great tools to check how to faster up your website. Their also provide best practice and guideline how to improve website loading performances.

Framework

————–

1. Zend framework : started using recently and fall in love with it. Strong MVC architecture support and database adapter.

2. jQuery : Javascript framework that i will use in every project that in the future. LOVE IT!!

CSS

—-

1. 960 Grid System from MIT. Very easy to use and faster up your layout  design for a new website without worrying if the new row or column will expand accordingly.

Forum

——–

1. Although this part is a bit not relevant, but i insist to introduce the best question and answer programming/IT forum : www.stackoverflow.com

2. Slashdot : Ah!!..sometimes you need a break from your IDE or notepad.

Time Tracker

—————-

1. I use RTM : Remember the Milk task list which integrate well with Gmail Task List.

2. Google Calendar : Use it for weekly planner and task remimder which sent free sms reminder to your mobile phone.

Written by Charles Ling

2 April, 2009 at 8:29 PM