CodeIgniter Forums
Output Minification (Minifying html,css,js) CI 3.x - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Output Minification (Minifying html,css,js) CI 3.x (/showthread.php?tid=61850)

Pages: 1 2


Output Minification (Minifying html,css,js) CI 3.x - nobitacnt - 05-24-2015

CI 3.x supports compression library or remove space html, css, js not?


RE: Output Minification (Minifying html,css,js) CI 3.x - John_Betong - 05-24-2015

(05-24-2015, 07:24 PM)nobitacnt Wrote: CI 3.x supports compression library or remove space html, css, js not?

Check the ./config/config.php settings:

PHP Code:
$config['compress_output'] = TRUE// FALSE === Defauilt; 



RE: Output Minification (Minifying html,css,js) CI 3.x - nobitacnt - 05-25-2015

I have configured
$config['compress_output'] = TRUE;
but view page source remains unchanged,still spaces
Thanks for support
demo: http://hocphp.info/CodeIgniter-3.0.0/index.php/welcome


RE: Output Minification (Minifying html,css,js) CI 3.x - cpittman - 05-25-2015

Are you worried about the HTML, or the CSS/JS? You should probably include your CSS and JS separately, and use a library for minification like https://github.com/slav123/CodeIgniter-minify.


RE: Output Minification (Minifying html,css,js) CI 3.x - Narf - 05-26-2015

Compression != minification.


RE: Output Minification (Minifying html,css,js) CI 3.x - John_Betong - 05-26-2015

(05-25-2015, 08:13 AM)nobitacnt Wrote: I have configured
$config['compress_output'] = TRUE;
but view page source remains unchanged,still spaces
Thanks for support
demo: http://hocphp.info/CodeIgniter-3.0.0/index.php/welcome

Try this to remove spaces, line-feeds, etc:

PHP Code:
//==============================================
function _maybe_compress_using_reference( & $result=''$return_result=false )
{
 
   $_SESSION['zzz_after' ''// strlen($result);
 
   $_SESSION['zzz_before'] = strlen($result);
 
   $search = array(
 
       '/\>[^\S ]+/s'  // strip whitespaces after tags, except space
 
       '/[^\S ]+\</s'  // strip whitespaces before tags, except space
 
       '/(\s)+/s'        // shorten multiple whitespace sequences
 
       );
 
   $replace = array(
 
       '>',
 
       '<',
 
       '\\1'
 
       );
 
   $result preg_replace($search$replace$result);
 
   // DOES NOT SHOW ADVERTS ?????
 
   // $hex=array("\x0D","\x0A");
 
   // $result=str_replace($hex,'',$result);

 
   $_SESSION['zzz_after'] = strlen($result);

 
   # Dab on end
 
   if(LOCALHOST): // DABS this on the end after </body></html>
 
     $result str_replace("</body></html>",''$result);

 
     $result .=  '<p class=\'clb\'> ONLY LOCALHOST <br /> Crunched output results:'
 
                   jj.js .'Before: '      number_format($_SESSION['zzz_before'])
 
                   jj.js .'After: &nbsp; 'number_format($_SESSION['zzz_after'])
 
                   jj.js .'Saving: '      number_format($_SESSION['zzz_before'] - $_SESSION['zzz_after']) .' bytes'
 
                   jj.js .'Percent: '     number_format(100 * ($_SESSION['zzz_before'] - $_SESSION['zzz_after']) / $_SESSION['zzz_before']) .' %'
 
               '</p>'
 
               '</body></html>';
 
   endif;

 
 // RETURNED BY REFERENCE
 
 // return $result;
}//endfunc 



RE: Output Minification (Minifying html,css,js) CI 3.x - gadelat - 05-26-2015

I advise you to not do this. It's resources intensive and prone to errors.


RE: Output Minification (Minifying html,css,js) CI 3.x - nobitacnt - 05-26-2015

Thanks for support, in wordpress plugins great Autoptimize (Optimizes your website, concatenating the CSS and JavaScript code, and compressing it.).If the library ci 3.x support like this is good


RE: Output Minification (Minifying html,css,js) CI 3.x - CroNiX - 05-27-2015

You can use tools like grunt to do that. It will take all of your various source css and js files, concatenate them into single files, minify them, etc. No need for a framework to reinvent the wheel when there are existing popular tools that do it. Just use existing technologies that are in wide use...like grunt. http://24ways.org/2013/grunt-is-not-weird-and-hard/


RE: Output Minification (Minifying html,css,js) CI 3.x - mwhitney - 05-27-2015

There are also some PHP libraries which will minify/concatenate CSS/JS files, like CssMin and JSMin. These are usually fairly easy to adapt for use in CI. When using these libraries, though, I would highly recommend checking for the output file(s) before loading/calling the library, so you only generate the file(s) as needed, and can easily supply a pre-minified file if there are any issues with the library's output.