Closed Thread
Results 1 to 5 of 5

Thread: Enable cache control (mod_expires) and gzip for site (blatmondo.x10.mx)

  1. #1
    davidmck77 is offline x10Hosting Member davidmck77 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Enable cache control (mod_expires) and gzip for site (blatmondo.x10.mx)

    Hi,

    I wanted to add cache control and gzip compression to my site (blatmondo.x10.mx).

    I've added this code to the .htaccess file, but it doesn't seem to work:
    ## Enable the mod_expires module
    ExpiresActive On
    ## Set expiration date to 1 month for all style sheets and images
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ## Set expiration date to 1 week for all HTML pages
    ExpiresByType text/html "access plus 1 week"
    ExpiresByType application/xhtml+xml "access plus 1 week"
    ### Apply a Cache-Control header to index.html
    <Files index.html>
    Header append Cache-Control "public, must-revalidate"
    </Files>

    ## compress text, html, javascript, css, xml:
    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

    ## Or, compress certain file types by extension:
    <Files *.html>
    SetOutputFilter DEFLATE
    </Files>

    Am I doing this correctly?
    Are these modules enabled for free hosting sites like mine?

    There are about five threads on the forum asking the same question, but none of them have an answer.
    Time t add it to the FAQs?

    Kind regards,
    David McKinnon
    Last edited by davidmck77; 07-10-2011 at 04:34 PM.

  2. #2
    davidmck77 is offline x10Hosting Member davidmck77 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Re: Enable cache control (mod_expires) and gzip or deflat for site (blatmondo.x10.mx)

    OK, so I partly solved this by fixing my own stupid mistake. :P
    Mac OS X doesn't allow files with a .prefix because they're reserved for system files and are usually invisible (I can probably change this in some way, but I'm not worrying about it now.)
    Long story short, I loaded the file "htaccess" and, because cPanel doesn't automatically refresh, thought I was replacing the ".htaccess" file. So I loaded "htaccess" and renamed it to ".htaccess" and mod_expires works just fine.

    Compression still doesn't work.
    I tried changing deflate in the above example to gzip:

    ## Enable the mod_gzip module
    <ifModule mod_gzip.c>
    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^application/x-javascript.*
    mod_gzip_item_exclude mime ^image/.*
    mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
    </ifModule>

    but no joy.

    Half fixed. Half to go. Any takers?
    Last edited by davidmck77; 07-11-2011 at 08:24 AM.

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,504

    Re: Enable cache control (mod_expires) and gzip for site (blatmondo.x10.mx)

    mod_gzip and mod_deflate are not currently loaded on the free hosts. Instead, you can pass the files you wish to compress through a script. For example:

    Code:
    <IfModule !mod_gzip.c>
        RewriteCond %{HTTP:Accept-Encoding} (^|,)gzip|deflate(,|$)
        RewriteCond %{REQUEST_FILENAME} -f
        RewriteRule ^/?(.*\.(html|js|css))$ /compress?u=/$1 [NS]
    </IfModule>
    compress.php:
    PHP Code:
    <?php
    if ($_GET['u'][0] != '/') {
        
    $_GET['u'][0] = '/' $_GET['u'][0];
    }
    // check that $_GET['u'] is safe to dump. For example:
    $path realpath(DOCUMENT_ROOT $_GET['u']);
    if (
    strpos($pathDOCUMENT_ROOT '/') !== 0) {
        
    header('HTTP/1.0 404 Not Found');
        exit();
    }
    // you'd also need to implement HTTP authorization if you have any resources on your site that are protected by it.

    if (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
        if (
    preg_match('/(^|,)\s*gzip\s*(,|$)/'$_SERVER['HTTP_ACCEPT_ENCODING'])) {
            
    ob_start('ob_gzhandler');
        } else if (
    preg_match('/(^|,)\s*deflate\s*(,|$)/'$_SERVER['HTTP_ACCEPT_ENCODING'])) {
            if (
    function_exists('ob_deflatehandler')) {
                
    ob_start('ob_deflatehandler');
            } else {
                
    $path "php://filter/read=zlib.deflate/resource=$path";
            }
        }
    }
    readfile($path);
    To configure Finder to show dotfiles, use:
    Code:
    defaults write com.apple.Finder AppleShowAllFiles YES
    You'll need to restart the Finder to see the change. You can do this with an applescript such as frogstomp's or the following:
    Code:
    set showFiles to ""
    try
    	set showFiles to do shell script ¬
    		"defaults read com.apple.finder AppleShowAllFiles"
    end try
    
    set dfltBtn to 1
    
    ignoring case
    	if {showFiles} is in {"ON", "TRUE", "1"} then
    		set dlgMsg to "Hidden Files (currently shown) ..."
    		set dfltBtn to 2
    	else if {showFiles} is in {"OFF", "FALSE", "0"} then
    		set dlgMsg to "Hidden Files (currently hidden) ..."
    	else
    		set dlgMsg to "Hidden Files..."
    	end if
    	
    	display dialog dlgMsg buttons {"Show", "Hide", "Cancel"} ¬
    		default button dfltBtn
    	copy the result as list to {buttonpressed}
    	
    	try
    		set restartFinder to 1
    		if the buttonpressed is "Hide" then
    			do shell script ¬
    				"defaults write com.apple.finder AppleShowAllFiles FALSE"
    		else if the buttonpressed is "Show" then
    			do shell script ¬
    				"defaults write com.apple.finder AppleShowAllFiles TRUE"
    		else if the buttonpressed is "Cancel" then
    			set restartFinder to 0
    		end if
    	end try
    end ignoring
    
    if restartFinder is 1 then
    	tell application "Finder" to quit
    	delay 1
    	tell application "Finder" to launch
    end if
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    davidmck77 is offline x10Hosting Member davidmck77 is an unknown quantity at this point
    Join Date
    Jun 2011
    Posts
    4

    Re: Enable cache control (mod_expires) and gzip for site (blatmondo.x10.mx)

    Many thanks Misson, that's a very comprehensive answer, and it's nice to finally know for sure if mod_gzip was installed -- and the Terminal command worked very nicely

    However, compression is still not working as far as I can tell.

    Here's what I've done so far.
    - added the
    Code:
    <IfModule !mod_gzip.c> ...
    code to the .htaccess file.
    - created a file called compress.php using the code you provided and placed it in the root directory with the .htaccess file.

    Is that all I have to do?

    I don't have any resources on the site which are protected by HTTP authorisation so I don't need to implement that.

    Google Page Speed and Port 80's Compression check both report that compression isn't enabled.
    Are these good ways to check?
    Last edited by davidmck77; 07-14-2011 at 08:59 AM.

  5. #5
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,504

    Re: Enable cache control (mod_expires) and gzip for site (blatmondo.x10.mx)

    You can check it directly using telnet. Send an HTTP request, making sure to include the Host and Accept-Encoding headers, and examine the response. You should be doing this anyway as you develop the script. As it says in my sig, any code I post is an example rather than a solution simply to be dropped in place. For example, in this case I don't bother to set a body for the 404 response or the Content-Encoding header. For another thing, I don't always test the code; it may have bugs. The constant DOCUMENT_ROOT, for instance, is likely not defined in your set up. You may need to use $_SERVER['DOCUMENT_ROOT'] instead. As another example, if you're using clean/extensionless URLs, the implementations of that and the compression feature above may conflict.
    Last edited by misson; 07-14-2011 at 03:11 PM.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

Closed Thread

Similar Threads

  1. How to enable gzip compression for my site?
    By wooflux15 in forum Free Hosting
    Replies: 0
    Last Post: 06-01-2011, 10:51 PM
  2. Enable gzip on my account.
    By publicpack41 in forum Free Hosting
    Replies: 6
    Last Post: 10-20-2010, 04:48 AM
  3. How to enable Gzip to my site
    By oldholborn8079 in forum Off Topic
    Replies: 3
    Last Post: 07-30-2010, 10:18 AM
  4. how to properly enable gzip compression/deflate
    By s5admin in forum Free Hosting
    Replies: 0
    Last Post: 04-10-2010, 01:47 PM
  5. GZip Compression for phpBB - Can I Enable it?
    By ibnuasad in forum Free Hosting
    Replies: 2
    Last Post: 07-29-2006, 06:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers