![]() |
Adding js, css files to header - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Adding js, css files to header (/showthread.php?tid=33060) |
Adding js, css files to header - El Forum - 08-13-2010 [eluser]BaRzO[/eluser] Hi All, I am trying to manage js, css file on the fly. For example welcome/index needs 2 js file and 1 css file but welcome/contact needs extra 1 js file and 1 css file. This dependencies changes because of some pages can have different jquery plugins. When user change any plugin in any page the needed files must loaded. How can I manage this. Pls help me. Thnks. Adding js, css files to header - El Forum - 08-14-2010 [eluser]harman[/eluser] hi , you can achieve this by Code: extends Controller Look@ Ci System\application\libraries than create MY_Controller.php Look Like this System\application\libraries\MY_Controller.php -----MY_Controller.php---- Code: class MY_Controller extends Controller { --------------------js.tpl.php Code: <sc type="text/javascript" language="javascript" src="<?php echo base_url() . 'your_Path/' . $filename . '.js'; ?>"></sc> ----------------in Controller Code: class Home extends MY_Controller { --------------in your welcome_message View Code: <html> //Same way You Also Do With CSS Note: i Placed "Script" to "sc" Please Correct That CI Editor Remove Script Word( Security Reasons) Adding js, css files to header - El Forum - 08-14-2010 [eluser]BaRzO[/eluser] Thnks for you reply ![]() Adding js, css files to header - El Forum - 08-14-2010 [eluser]cahva[/eluser] ..or use something like Carabiner which lets you add css and js you need from controller easily. BTW, js should go just before end of body tag and css to head. Its no biggie but pages "seems" to load faster because html is rendered before loading js if you put them to the end of page. Adding js, css files to header - El Forum - 08-14-2010 [eluser]BaRzO[/eluser] Thank you cahva i did not know that. I will check it. |