• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Output Minification (Minifying html,css,js) CI 3.x

#1
CI 3.x supports compression library or remove space html, css, js not?
Hocphp.info - Learn Codeigniter starting from the basics correctly with this Codeigniter tutorial
Reply

#2
(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; 
Reply

#3
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
Hocphp.info - Learn Codeigniter starting from the basics correctly with this Codeigniter tutorial
Reply

#4
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.
Reply

#5
Compression != minification.
Reply

#6
(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 
Reply

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

#8
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
Hocphp.info - Learn Codeigniter starting from the basics correctly with this Codeigniter tutorial
Reply

#9
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/
Reply

#10
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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.