htaccess caching code – Speed Boost Cache Code

Home Forums BulletProof Security Pro htaccess caching code – Speed Boost Cache Code

This topic contains 11 replies, has 6 voices, and was last updated by Avatar of Akhil K A Akhil K A 6 months, 2 weeks ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #8652 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    Give this code a test drive – do benchmark tests with Firefox, Firebug, Firephp and Yslow.  You may see a minor website load speed improvement or a significant website load speed improvement.

    1. Copy the Speed Boost .htaccess code into this Custom Code text box: CUSTOM CODE TOP PHP/PHP.INI HANDLER/CACHE CODE: Add php.ini handler and/or plugin cache code here and click the Save Root Custom Code button.

    2. Go to the BPS Security Modes page and click the Create secure.htaccess File AutoMagic button and then activate Root Folder BulletProof Mode.

    NOTES: If you are using a php/php.ini handler in your root .htaccess file then it should also be added/copied to BPS Custom Code.  Copy this Speed Boost Cache code below your php/php.ini .htaccess code.  If you are using a caching plugin that creates .htaccess caching code then you can also add that plugin’s caching code directly above this Speed Boost caching code.  The order of the code is:  1. php/php.ini handler .htaccess code (if you have php/php.ini handler code), 2. caching plugin .htaccess cache code (if you are using a caching plugin) and then this Speed Boost .htaccess code.

    # BEGIN WEBSITE SPEED BOOST
    # Time cheat sheet in seconds
    # A86400 = 1 day
    # A172800 = 2 days
    # A2419200 = 1 month
    # A4838400 = 2 months
    # A29030400 = 1 year
    
    # Test which ETag setting works best on your Host/Server/Website
    # with Firefox Firebug, Firephp and Yslow benchmark tests.
    
    # Create the ETag (entity tag) response header field
    #FileETag MTime Size
    
    # Remove the ETag (entity tag) response header field
    Header unset ETag
    FileETag none
    
    <IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType image/jpg A4838400
    ExpiresByType image/gif A4838400
    ExpiresByType image/jpeg A4838400
    ExpiresByType image/png A4838400
    ExpiresByType video/webm A4838400
    ExpiresByType application/x-shockwave-flash A4838400
    ExpiresByType application/x-javascript A4838400
    ExpiresByType application/javascript A4838400
    ExpiresByType text/javascript A4838400
    ExpiresByType text/css A4838400
    #ExpiresByType text/html A86400
    # Default is 2 days below so the line above is not needed / commented out
    ExpiresDefault A172800
    </IfModule>
    
    <IfModule mod_headers.c>
    <FilesMatch "\.(js|css|flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav|gif|jpg|jpeg|png|swf|webm)$">
    Header append Cache-Control "public"
    </FilesMatch>
    <FilesMatch "\.(txt|html)$">
    Header append Cache-Control "proxy-revalidate"
    </FilesMatch>
    <FilesMatch "\.(php|cgi|pl|htm|xml)$">
    Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
    Header set Pragma "no-cache"
    </FilesMatch>
    </IfModule>
    
    <IfModule mod_deflate.c>
    # Insert filters
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php
    AddOutputFilterByType DEFLATE application/x-httpd-fastphp
    AddOutputFilterByType DEFLATE image/svg+xml
    
    # Drop problematic browsers
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    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
    </IfModule>
    # END WEBSITE SPEED BOOST

    You can use the code exactly as is or if you want to see if you can get a couple more milliseconds of speed:
    Test using no ETags by commenting out (adding a pound sign #) all the ETag lines of .htaccess code below (#FileETag MTime Size, #Header unset ETag, #FileETag none) and benchmark test website performance, then benchmark test using Header unset and FileETag none (this is currently the default code shown below) and then benchmark test using FileETag MTime Size (uncomment FileETag MTime Size and comment out #Header unset ETag, #FileETag none).  Whichever ETag combination/choice makes your website perform the fastest is the one you want to use/keep.  On Go Daddy it seems that using Header unset ETag and FileETag none is slightly faster in milliseconds (as shown below).

    Testing examples explained above are here:  http://forum.ait-pro.com/forums/topic/htaccess-caching-code-speed-boost-cache-code/#post-9707

    #9547 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    Question copied from another topic to this relevant topic:

    Whichever ETag combination/choice makes your website perform the fastest

    On Go Daddy it seems…

    Do you have practical knowledge what’s best on 1and1 managed servers?

    Nane

    #9550 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    Nope, each person will have to test whichever works best for their Host and if you want to post back here that would be great to help other folks out.

    #9593 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of Juan Pablo
    Juan Pablo
    Participant

    Hi, i don’t understand what i must do it.

    Can you clarify, what i must do?.

    Thanks in advance.

    #9594 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    Watch this Custom Code Video Tutorial.  If you still have any questions after watching the video tutorial then post those questions.

    http://forum.ait-pro.com/video-tutorials/#custom-code

    #9705 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of Blair Wolf
    Blair Wolf
    Participant

    I have been dicking with this for half a day trying to figure out what I’m supposed to comment out/in. I don’t get it and the video was no real help. Remember, most of us are not engineers or have degrees in computer science. What is “Header unset” and “FileETag MTime Size” and what does it look like in that list of code or in short WTF am I doing.

    Just goes to show you if you don’t put it layman terms, so everyone can understand it, you get a lot of stupid questions.

    #9707 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    Ok let me try and make this a no-brainer.

    The first test should be done with all of these things below commented out with pound signs #

    # Test which ETag setting works best on your Host/Server/Website
    # with Firefox Firebug, Firephp and Yslow benchmark tests.
    
    # Create the ETag (entity tag) response header field
    #FileETag MTime Size
    
    # Remove the ETag (entity tag) response header field
    #Header unset ETag
    #FileETag none

    The next test should be done with these things commented out

    # Test which ETag setting works best on your Host/Server/Website
    # with Firefox Firebug, Firephp and Yslow benchmark tests.
    
    # Create the ETag (entity tag) response header field
    FileETag MTime Size
    
    # Remove the ETag (entity tag) response header field
    #Header unset ETag
    #FileETag none

    The final test should be done with these things uncommented/commented out because most likely this is going to be the optimum choice.

    # Test which ETag setting works best on your Host/Server/Website
    # with Firefox Firebug, Firephp and Yslow benchmark tests.
    
    # Create the ETag (entity tag) response header field
    #FileETag MTime Size
    
    # Remove the ETag (entity tag) response header field
    Header unset ETag
    FileETag none
    #10084 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of Zac
    Zac
    Participant

    So the first step is to test the code.. having all the *test instructions disabled with the pound symbol “comment out”.

    And what are we to observe after this step?

    Step 2, same thing only this is enabled (FileETag MTime Size) by the removal of # comment tag.

    And again, why are we doing this or what am I to observe from this test?

    Step 3: Is even more confusing, we are suppose to enable or disable what? You have only requested that we enable the one line of code in step 2, and somehow we should know what to disable or enable. How does step one, (no changes) and step 2 lead to step 3′s list of optimal settings?

    #10105 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    @ Zac – Ok how about this for simple:  Use the code exactly as it is and it will work fine.  Benchmarking speed testing would be done using Firefox and these Firefox add-ons:  Firebug, Firephp and YSlow.  This is actually not really necessary because the difference in speed is going to be only a couple of milliseconds difference max, so therefore it is not really necessary to benchmark test for a speed differences since a couple of milliseconds is going to be completely insignificant for most folks.  Some folks care about a couple of milliseconds, but most do not.  ;)

    #10506 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of Tim McGuinness
    Tim McGuinness
    Participant

    AIT,

    Look you guys are brilliant.  You have kept my sites hack free for 2 years and counting now! [knock on wood], but you are not the most user friendly designers.  You basic security plugin is a nightmare for novices.  Think ONE CLICK.

    This is a perfect example.  I gave up on your speed fix, after having broken a couple of sites.  The restore wasn’t a problem, but it points out that you need this in a plugin with a single click interface.  I won’t mind paying for it – but keep life simple for those of us that have to maintain our sites.

    #10524 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of AITpro Admin
    AITpro Admin
    Keymaster

    @ Tim McGuinness – we have taken your thoughts into consideration.  Thank you.

    #12424 Facebook Google Twitter Email Stumbleupon Digg reddit pinterest Myspace Delicious LinkedIn tumblr
    Avatar of Akhil K A
    Akhil K A
    Participant

    WOW.. I got speed boost.. 7sec to 4sec.

    Thanks, and I support Tim McGuinness suggestion.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.