How to Speed Up CodeIgniter App?

You can use some step for sppdup codeigniter application.

  • Enable Gzip Compression
  • Enable full page Cache
  • Enable HTML output Compress
  • leverage browser caching
  • Enable Gzip Compression

    Go to application/config/config.php, Then Enable Gzip compression by setting compress_output value to TRUE in ci config array.
    $config['compress_output'] = TRUE;

    Enable full page Cache

    We can Enable full page Cache to entire Controller by calling $this->output->cache(30); in the controller constructor, or we enable it in function level by calling with in the method.

    Full page Cache system create a Cached version of the HTML page in cache folder,

    Cache folder should be writable by the web server

    $this->output->cache(30);
    // Will expire in 30 minutes

    Enable HTML output Compress

    we gonna use CodeIgniter Hooks to minify HTML output, go to application/hooks/ create a file called compress.php, copy past the below code.

    File name : index.php

    function compress()
    {
    $CI =& get_instance();
    $buffer = $CI->output->get_output();
    $search = array(
    '/>[^S ]+/s',
    '/[^S ]+</s',
    '/(s)+/s', // shorten multiple whitespace sequences
    '#(?://)?<![CDATA[(.*?)(?://)?]]>#s' //leave CDATA alone
    );
    $replace = array(
    '>',
    '<',
    '\1',
    "//&lt;![CDATA[n".'1'."n//]]>"
    );
    $buffer = preg_replace($search, $replace, $buffer);
    $CI->output->set_output($buffer);
    $CI->output->_display();
    }

    till now we have created a hook function , now we have to declare it hooks config go to application/config/hook.php

    $hook['display_override'][] = array(
    'class' => '',
    'function' => 'compress',
    'filename' => 'compress.php',
    'filepath' => 'hooks'
    );

    The final step is go to application/config/config.php file, in the config array , enable hooks.





    Previous Next


    Trending Tutorials




    Review & Rating

    0.0 / 5

    0 Review

    5
    (0)

    4
    (0)

    3
    (0)

    2
    (0)

    1
    (0)

    Write Review Here