Enqueue JavaScript and CSS Styles in CodeIgniter with a simple, lightweight library.
- Add
enqueue.php
toYOUR/APP/PATH/application/libraries/
- Add
enqueue
to the array on Line 55:$autoload['libraries'] = array();
inYOUR/APP/PATH/config/autoload.php
- In your theme file(s) add
$this->enqueue->loadjs();
and$this->enqueue->loadcss();
where you would like to load enqueued scripts.
Add JS and CSS files to YOUR/APP/PATH/public/js/
and YOUR/APP/PATH/public/css/
, respectively. If these folders don't exist you will need to create them.
In your controllers or models add:
$this->enqueue->enqueue_js('JS_FILENAME');
to enqueue JavaScript$this->enqueue->enqueue_css('CSS_FILENAME');
to enqueue CSS