SmartLoader
, (*1)
SmartLoader is a library that allows you to easily manage your js and css on your site., (*2)
When you have lot of js & css to include dynamically, itâs difficult and complex. With SmartLoader, you have some functions to enqueue code or links in controllers and you just have to output the queue in your footer., (*3)
If you know wordpress development, this library works like the wp_enqueue function. In your controller, you can enqueue some js and css link, and output this in footer., (*4)
Installation
Create composer.json
file
Add, (*5)
{
"require": {
"remiheens/smartloader": "2.0.*@dev"
}
}
Documentation
The object "SmartLoader" has two objects: "js" and "css", these two attributes are the managers for CSS and Javascript., (*6)
public function setTemplate($tpl);
set the template folder, (*7)
public function getTemplate();
get the template folder, (*8)
public function forceHTTP();
force http because by default output link starts woith "//domain.tld/...", (*9)
JS
public function setTemplate($tpl);
set the template name, each js will be loaded into this directory template, (*10)
public function forceHTTP();
force http because by default output link starts woith "//domain.tld/...", (*11)
public function add($args);
Add js file url or an array of url, (*12)
public function loadLib($lib);
add a js library juste the name located in template_folder/js/lib/ (see configuration)., (*13)
public function jquery($data, $header = false);
Add jquery code in header or footer, (*14)
public function js($data, $header = false);
Add javascript code in header or footer, (*15)
public function load($js_file);
load a js like a view, SmartLoaderJS try to get this file into the configurated js folder (name without .js), (*16)
public function loadLinks();
Output the list of script balise for all js link added, (*17)
public function loadJavascript($header = false);
Output javascript code, (*18)
CSS
public function setTemplate($tpl);
set the template name, each js will be loaded into this directory template, (*19)
public function forceHTTP();
force http because by default output link starts woith "//domain.tld/...", (*20)
public function add($args);
Add css file url, (*21)
public function output();
Output the link balise ref to css compiled file., (*22)
Each CSS added + autoload folder are concatenated to a css file into compiled folder. It wil be regenerated if on file are modify, (*23)