Improve Response Time with Header Cache

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 Bootstrap 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.


protected function _initResponse()
{

  // Create a new HTTP response object
  $response = new Zend_Controller_Response_Http();

  // Set the response headers : the value below are only set for example.
  $response->setHeader('language', 'en')
           ->setHeader('content-language', 'en')
           ->setHeader('Content-Type', 'text/html; charset=utf-8')
           ->setHeader('Accept-Encoding', 'gzip, deflate')
           ->setHeader('Expires', 'max-age=7200, must-revalidate’, true)
           ->setHeader('Cache-Control', 'public', true)
           ->setHeader('Cache-Control', 'max-age=7200') //only for testing
           ->setHeader('Pragma', '', true);

  // Assign the response to the front controller
  $this->getPluginResource(’frontController’)->getFrontController()->setResponse($response);
}

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

Advertisements

About Charles Ling
Web/Android/IPhone Developer. Very very interested in Web Architecture, Web Standard and and how to use Web to improve human social life and doing cool stuff.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: