Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Compression in Apache and improving page speed

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 542
    Comment on it

    Apache provides mod_deflate module to compress the response prior to sending it to client by attaching the DEFLATE output filter in filter chain.

    Following is a simple sample configuration for compressing selected text-based content types :

    AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript
    

    mod_deflate implements compression by attaching the DEFLATE filter in the filter chain.

    SetOutputFilter directive can be used to enable the compression.

    SetOutputFilter DEFLATE

    To restrict the compression to particular MIME types, AddOutputFilterByType directive can be used.

    Example :

    <Directory "/">
        AddOutputFilterByType DEFLATE text/html
    </Directory> 
    

    Some popular browsers cannot handle compression, use the BrowserMatch directive comes handy.

    Example :

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    

    At first we probe for a User-Agent string that designates a Netscape Navigator version of 4.x. These versions are not able to handle compression of types apart text/html. The versions 4.06, 4.07 and 4.08 additionally have quandaries with decompressing html files. Thus, we thoroughly turn off the deflate filter for them.

    The third BrowserMatch directive fine-tunes the conjectured identity of the User agent, because the Microsoft Internet Explorer identifies itself additionally as "Mozilla/4" but is genuinely able to handle requested compression. Therefore we match against the supplemental string "MSIE" (\b denotes "word boundary") in the User-Agent Header and turn off the restrictions defined afore.

    Dealing with proxy servers

    The mod_deflate module sends a Vary: Accept-Encoding HTTP response header to vigilant proxies that a cached response should be sent only to clients that send the opportune Accept-Encoding request header. This averts compressed content from being sent to a client that will not understand it.

    If some special exclusions are in use which are dependent on say, the User-Agent header, an addition to the Vary header to alert proxies of the additional restrictions must be configured manually. For example, in a typical configuration where the addition of the DEFLATE filter depends on the User-Agent:
    Header append Vary User-Agent

    Improving page speed

    While compressing content by mod_deflate or mod_gzip(in apache 1.3.xx) can improve page speed, others measures can also be taken to improve page speed significantly. Some of the most common used methods are :

    Minimize number of javascript and css files : If multiple javascript files are in use, combine these in a single javascript file. Same is applicable to css files. This will reduce the number of http requests resulting in the faster page load.

    Minify the javascript : Javascript code can be minified to reduce the size of file size.

    Use sprite images : If some images are common across multiple pages such as icons, etc., they should be in sprite format so that all the images can be fetched in a single http request. These images can be managed later on the page by CSS.

    Additionally, using compression will further reduce the size again results in improved page speed.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: