Adding js, css files to header |
[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.
[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)
[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.
[eluser]BaRzO[/eluser]
Thank you cahva i did not know that. I will check it. |
Welcome Guest, Not a member yet? Register Sign In |