Speed Up your Web Application by CodeIgniter
Now a days one of the big issue you have to focus that to High speed your web site performance. I have read a nice article” Performance tips for web applications” where focus the performance tips of web application. These tips can easily apply by codegIniter . Let see some of the tips below.
Some of the techniques are :
- Enable GZIP Components.
- Make Fewer Http Request .
- Adds an Expires Header.
Enable GZIP Component :
In the system/application/config.ph
change the config variable true
Make Fewer HTTP Request :
1. Caching the site.
Each time file loads from your web server, it generates an http request. So you can reduce number of http requests by caching some contents which are almost static or changes very rarely. if these contents are loaded from browser cache, there will be no request for them over HTTP.
So you can easily caching your web Pages in the CodeIgniter :
To enable caching, put the following tag in any of your controller functions:
Where n is the number of minutes you wish the page to remain cached between refreshes.
The above tag can go anywhere within a function. It is not affected by the order that it appears, so place it wherever it seems most logical to you. Once the tag is in place, your pages will begin being cached.
To set data you can do it by the
Also you can manually set header :
Permits you to manually set server headers, which the output class will send for you when outputting the final rendered display. Example:
2. join multiple css or js file into single css or js file .
It can be done in many ways . But in the CodeIgniter forum i find some ways to do that . You can check out here. The below code is the forum message :
Following is the controller to join multiple cs or jss
file in to one, and hence making fewer server request to speed up the things little bit.
Just add following in to your controllers. save as file.php Set the path of your
js and css files accordingly.
Now you can add any number of files with just single line of code,and with single
For e.g. If you want to include two css file , foo.css and bar.css , the code is ,
The alternative of that one is :
got a script from somewhere that gzips the css/js, caches the compilation of the files etc. Since I generally use jQuery I my controller also has the function jQuery. I can now do
<?PHP echo site_url(asset/jquery); ?>
This redirects to a similar function as you have but a bit shorter.
Adds an Expires Header:
you can add expire header by the Ci library output class.