Wednesday, September 24, 2008

Removing HTML tags from strings in Javascript

To remove html tags from a string use following code snippet:

function StripHTMLTags(strSrc)
{
strSrc.replace( /<[^<|>]+?>/gi,'' );
}

Sunday, September 21, 2008

Image Caching in Apache Webserver

Using Apache with the mod_expire module, you can define the Webserver to allow the client to “cache” images, including java script and CSS files.
This greatly improves the load-time of the website.
To enable edit the httpd.conf and define:
enable mod_expire module

    LoadModule expires_module modules/mod_expires.so

there are different way of configuring caching in apache.

Caching Files by Extension:

ExpiresActive On
   <Directory "/home/website/public_html">
Options FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
ExpiresDefault A300
<FilesMatch "\.html$">
Expires A86400
</FilesMatch>
<FilesMatch "\.(gif|jpg|png|js|css)$">
Expires A2592000
</FilesMatch>
</Directory>

Caching Files by MIME Type:

ExpiresActive On
ExpiresByType text/java script “access plus 1 day”
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000

Now restart apache. ExpiresDefault A300 sets the default expiry time to 300 seconds after access (A). Using M300 would set the expiry time to 300 seconds after file modification. Above setting will cache gif,jpg, png images for 259200 seconds(30 days) after access(A signifies access).

Saturday, September 6, 2008

PHP Framework

For a long time, I am using asp.net to build dynamic website. But recently for a project I need to move to php. Being a asp.net geek, I found it very difficult to work in php. But after some search I found a great php framework Prado. I was really amazed that these guys have build such a great framework. Now I can feel at home.

PRADO is a component-based and event-driven programming framework for developing Web applications in PHP 5. The sole requirement to run PRADO-based applications is a Web server supporting PHP 5.1.0 or higher. And above all "It is free!". PRADO is best suitable for creating Web applications that are highly user-interactive. It can be used to develop systems as simple as a blog system to those as complex as a content management system (CMS) or a complete e-commerce solution.

Installation of PRADO mainly involves downloading and unpacking.

  1. Go to pradosoft.com to grab the latest version of PRADO.
  2. Unpack the PRADO release file to a Web-accessible directory.
Your installation of PRADO is done and you can start to play with the demo applications included in the PRADO release via URL http://web-server-address/prado/demos/. Here we assume PRADO is unpacked to the prado subdirectory under the DocumentRoot of the Web server.

Saturday, August 23, 2008

There are many articles on the web about how to improve performance of website running on apache webserver. But I summarize here, so that you can start directly using them:
  1. Remove all 404 file references
  2. Remove duplicate javascript and css references
  3. Remove unnecessary images
  4. Minify all javascripts and css. There are many tools available to do this, but my personal favourite is YUI Compressor
  5. Enabling gzip compression. To do this you need to make some changes in apache configuration file(httpd.conf but you can also do it in .htaccess file). To enable gzip compression in apache enable module mod_deflate in httpd.conf. you can do this by removing semicolon before this entry LoadModule deflate_module modules/mod_deflate.so

    Add following entry at the end of the httpd.conf:


    SetOutputFilter DEFLATE
    SetInputFilter DEFLATE

    # Netscape 4.x has some problems...
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    # Netscape 4.06-4.08 have some more problems
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    # MSIE masquerades as Netscape, but it is fine
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

    # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
    # the above regex won't work. You can use the following
    # workaround to get the desired effect:
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

    # Make sure proxies don't deliver the wrong content
    #Header append Vary User-Agent env=!dont-vary


    # The two lines above compress everything unless excluded below.
    SetEnvIfNoCase Request_URI \.(?:gif|jpeg|png|jpg)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.plist$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI \.swf$ no-gzip dont-vary
    # Below is an example where you get rid of what's above and you explicity compress.
    AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd- fastphp application/x-httpd-eruby text/html text/javascript

    DeflateFilterNote ratio
    DeflateCompressionLevel 9


    There are still many things that should be done to improve site performance. I will write about them in my next article.

Hope this helps