Improve Response Time with Header Cache
11 May, 2009 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 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 :
Second Reload Result :