Welcome Guest, Not a member yet? Register   Sign In
Gzip in pages?
#1

[eluser]Lovecannon[/eluser]
Okay, Im using this to GZIP my pages...
Code:
function acceptsGZip(){
    $accept = str_replace(" ","",
        strtolower($this->input->server('HTTP_ACCEPT_ENCODING'))
    );
    $accept = explode(",",$accept);
    return in_array("gzip",$accept);
    }
    
    function obOutputHandler($OutputHtml){
    global $EnableGZipEncoding;
    //-- Play with HTML before output
    //-- If GZIP not supported compression is pointless.
    // If headers were sent we can not signal GZIP encoding as
    // we will mess it all up so better drop it here!
    // If you disable GZip encoding to use plain output buffering we stop here too!
    if(!acceptsGZip() || headers_sent() || !$EnableGZipEncoding) return $OutputHtml;
    //-- We signal GZIP compression and dump encoded data
  
    return gzencode($OutputHtml);
}
$this->output->set_header("Content-Encoding: gzip");
ob_start("obOutputHandler");
It works if I manual output scripts..css..html..but if I use $this->load->view, nothing is generated...can anyone give me an example of how to GZIP content sent through $this->load->view?
#2

[eluser]Lovecannon[/eluser]
I fixed everything, so cancel this
#3

[eluser]AtlantixMedia[/eluser]
can you share your solution? I will soon need to do this as well. thanks
#4

[eluser]Lovecannon[/eluser]
Well apparently, the function I was using for GZIP wasn't working, so I just used PHPs build in ob_gzhandler, so just add this at the far beginning (Before any HTML) of any view you want GZIPped
Code:
<?php
ob_start("ob_gzhandler");
?>
or if your doing it directly from your controllers:
Code:
ob_start("ob_gzhandler");
Very, very, simple. I had made it difficult by trying to use my own GZIP compression functions, which apparently don't work. =\
#5

[eluser]AtlantixMedia[/eluser]
ok, just a regular ob_start("ob_gzhandler"); then. thanks
#6

[eluser]Lovecannon[/eluser]
No prob.
#7

[eluser]alexsancho[/eluser]
I don't know if i'm loosing anything here, but.. why not simply enable it on config and let CI do the job?

Code:
/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads.  When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| VERY IMPORTANT:  If you are getting a blank page when compression is enabled it
| means you are prematurely outputting something to your browser. It could
| even be a line of whitespace at the end of one of your scripts.  For
| compression to work, nothing can be sent before the output buffer is called
| by the output class.  Do not "echo" any values with compression enabled.
|
*/
$config['compress_output'] = TRUE;
#8

[eluser]AtlantixMedia[/eluser]
this is even better. thanks!. new to CI...
#9

[eluser]Lovecannon[/eluser]
I completely forgot about the built in compressor -_-'. I feel like an idiot now lol.




Theme © iAndrew 2016 - Forum software by © MyBB