1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to Speed up your website & save bandwidth with a simple apache .htaccess change

Discussion in 'Blogging' started by kilaz, Sep 8, 2009.

  1. kilaz

    kilaz Jr. VIP Jr. VIP

    Joined:
    Aug 15, 2009
    Messages:
    876
    Likes Received:
    382
    Home Page:
    Hi Guys.. I've been using this method on several of my other sites to speed up my page load times and I tried it on my wordpress blogs with great results. It also decreases bandwidth usage.

    I don't recall where I found this info since its been a while but I thought you guys might find it useful.

    Basically what happens is Apache sends the website .css and .js code sent to the browser compressed and then the web browser un-compress's the file and loads it. You can add other file types like .php and .html files.

    In .htaccess add these lines.
    Code:
    #PHP4 Support to enable zlib compression.
    <ifModule mod_php4.c>
    php_value zlib.output_compression 16386
    </ifModule>
    
    #PHP5 Support to enable zlib compression.
    <ifModule mod_php5.c>
    php_value zlib.output_compression 16386
    </ifModule>
    
    #This section tells Apache what files to compress and send. 
    #Notice I only have .js and .css in here since
    #there's no need to compress .jpg and other already compressed files. 
    #If you want to add other file types like php and html change 
    #the FilesMatch line to this <FilesMatch "\.(css¦js¦x?html?¦jsp)$">; 
    <IfModule mod_deflate.c>
    <FilesMatch "\.(js|css)$">
    SetOutputFilter DEFLATE
    </FilesMatch>
    </IfModule>
    
    That&#8217;s pretty much it.. You can test your results by going to
    http://websiteoptimization.com/services/analyze/

    In some cases my page load times were cut in HALF. Your results may vary depending on large your files are and which files you choose to compress but all the sites I&#8217;ve implemented this on I&#8217;ve seen an improvement. The only caveat is that really old browsers like Windows Explorer V1 may not know how to handle this method but since I get very few of those visitors the gain much more outweighed any loss in those positional visitors!

    I&#8217;m not an expert with the above method so if someone can add any more information please do. There&#8217;s also several websites that offer info on this topic if you google for &#8220;php zlib compression&#8221;

    If it helps you just hit the thanks button :)
    -K-
     
    • Thanks Thanks x 9
    Last edited: Sep 8, 2009
  2. wozney

    wozney Registered Member

    Joined:
    Dec 31, 2007
    Messages:
    64
    Likes Received:
    7
    going to try this out and see if it works for my sites...thanks for the info appreciate it
     
  3. IamNomad

    IamNomad Junior Member

    Joined:
    Mar 27, 2009
    Messages:
    135
    Likes Received:
    22
    Location:
    ┌∩┐(◕_◕)┌∩┐
    Another good tweak thats powered by .htacess is to enable server side cacheing.

     
  4. GTP_Smile

    GTP_Smile Registered Member

    Joined:
    Jun 15, 2009
    Messages:
    85
    Likes Received:
    8
    Isn't there a plugin that does this?
    such as WP Super Cache ..would take care of it?
     
  5. kilaz

    kilaz Jr. VIP Jr. VIP

    Joined:
    Aug 15, 2009
    Messages:
    876
    Likes Received:
    382
    Home Page:
    Yes as far as setting up a cache but not with using the zlib stuff. I use WPSuperCache and the above methods I posted with my WP blogs. Between the two its really made them faster.

    -k-
     
  6. GTP_Smile

    GTP_Smile Registered Member

    Joined:
    Jun 15, 2009
    Messages:
    85
    Likes Received:
    8
    By any chance, do you know offhand of an app or browser extension that could measure load times? I could use it just as a comparison betw diff setups. This is a nice meth, thx given. Actually had a post about page loading a while back but no response.
     
    Last edited: Sep 8, 2009
  7. IamNomad

    IamNomad Junior Member

    Joined:
    Mar 27, 2009
    Messages:
    135
    Likes Received:
    22
    Location:
    ┌∩┐(◕_◕)┌∩┐
    actually, wpcache, wpsupercache does something completely different from my example .It doesn't touch .htaccess for server side caching. It uses do_cacheaction() and add_cacheaction() functions in php and takes is another way to implementing gzip. The originals poster uses apache which is less intensive php. Also, My example doesn't depend on php to determine cache. Both are better for large websites.

    http://websiteoptimization.com/services/analyze/

    gives detailed times and suggestions.
     
    Last edited: Sep 8, 2009
  8. The Scarlet Pimp

    The Scarlet Pimp Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 2, 2008
    Messages:
    788
    Likes Received:
    3,129
    Occupation:
    Chair moistener.
    Location:
    Cyberspace
    this line doesn't look right...

    <FilesMatch "\.(css¦js¦x?html?¦jsp)$">;

    should it be,

    <FilesMatch "\.(js|css|html|php)$"> ????
     
  9. IamNomad

    IamNomad Junior Member

    Joined:
    Mar 27, 2009
    Messages:
    135
    Likes Received:
    22
    Location:
    ┌∩┐(◕_◕)┌∩┐
    in the above example its commented out. I believe you are correct on the "bar" character though
     
  10. angelas111

    angelas111 Jr. VIP Jr. VIP Premium Member

    Joined:
    Jan 4, 2009
    Messages:
    1,570
    Likes Received:
    1,016
    Location:
    ohio
    Cool, going to try this. I have several wordpress sites and some of them load slow as shit.
     
  11. The Scarlet Pimp

    The Scarlet Pimp Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 2, 2008
    Messages:
    788
    Likes Received:
    3,129
    Occupation:
    Chair moistener.
    Location:
    Cyberspace
    what about the "x" and that "?"...
     
  12. IamNomad

    IamNomad Junior Member

    Joined:
    Mar 27, 2009
    Messages:
    135
    Likes Received:
    22
    Location:
    ┌∩┐(◕_◕)┌∩┐
    I believe thats correct. it another way of saying do this when xhtml or html are the extension.