Once the PHP classes are registered, the next step is to generate the corresponding javascript and CSS code. Jaxon provides 3 different functions for this purpose.
- The function
jaxon()->getCss()returns the CSS code to insert into the page. This will often be instructions to load CSS files of Jaxon plugins. - The function
jaxon()->getJs()returns the code to load external javascript files. - The function
jaxon()->getScript()returns the javascript code corresponding to registered functions and classes, and the configuration of the library.
The separation into three distinct functions makes it possible to insert the codes generated by the Jaxon library in different parts of the HTML page.
The call to jaxon()->getScript(true, true) returns the cumulative output of the three previous calls.
Writing the Javascript code in a file
When the js.app.export option is set to false, the generated javascript and CSS code is directly included into the HTML code of the page.
If this option is set to true, the .js and .css files are created in the directory indicated by the js.app.dir option,
and the jaxon()->getScript() and jaxon()->getCss() functions return the HTML code to load these files from the URL indicated by the js.app.uri option.
If in addition, the js.app.minify option is set to true, the code is minified and the file names end with .min.js and .min.css.
By default, the files name is generated using a hash on a value computed by the library.
If the js.app.file option is defined, its value is used as the file name.
The javascript and CSS files will not be regenerated if they already exist.
It is then recommended to set the js.app.export option to false when developing, and generate the minified files when deploying the application.