Welcome Guest, Not a member yet? Register   Sign In
A quick & ugly way to join multiple css or js file.
#1

[eluser]gops[/eluser]
Following is the controller I created to join multiple cs or jss
file in to one, and hence making fewer server request to speed up the things little bit.

Just add following in to your controllers. save as file.php Set the path of your
js and css files accordingly.
Code:
<?php
class File extends Controller
{
    function File()
    {
        parent::Controller();
                /*Set your own path here*/
        $this->_path = "./public/";    
    }
    function index()
    {
        echo "";
    }
    function js()
    {
        $segs = $this->uri->segment_array();
        foreach ($segs as $segment)
        {
            $filepath = $this->_path.$segment.'.js';
            if(file_exists($filepath))
            {
                readfile($filepath);
            }
        }
    }
    function css()
    {
        $segs = $this->uri->segment_array();
        foreach ($segs as $segment)
        {
            $filepath = $this->_path.$segment.'.css';
            if(file_exists($filepath))
            {
                readfile($filepath);
            }
        }
    }
}
?>
Now you can add any number of files with just single line of code,and with single
request.
For e.g. If you want to include two css file , foo.css and bar.css , the code is ,
Code:
<link rel='stylesheet' type='text/css' media='all' href='<?php echo site_url("file/css/foo/bar");?>' />
And same way for javascript , just replace js with css.


I would like to know, is there better &/or easy way to do same ?
is this a good idea ?


Messages In This Thread
A quick & ugly way to join multiple css or js file. - by El Forum - 11-02-2007, 03:00 AM
A quick & ugly way to join multiple css or js file. - by El Forum - 11-02-2007, 03:06 AM
A quick & ugly way to join multiple css or js file. - by El Forum - 11-02-2007, 03:26 AM
A quick & ugly way to join multiple css or js file. - by El Forum - 11-02-2007, 04:27 AM
A quick & ugly way to join multiple css or js file. - by El Forum - 11-02-2007, 04:48 AM
A quick & ugly way to join multiple css or js file. - by El Forum - 11-04-2007, 01:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB