BigTree comes with a built in JavaScript preprocessor with support for variables, minifying, and combining files.
Creating Processed JS Files
To create a processed JS file you'll need to add arrays to your configuration variable. In the below example, we're going to create http://www.website.com/js/site.js by including jquery.js and main.js.
$bigtree["config"]["js"]["files"]["site"] = array( "jquery.js", "main.js" );
For this example, site.js will first include jquery.js and then main.js. If any of the files changes, the cache will be destroyed and users will be served a new copy.
Configuration Settings
To turn on JS minifying, set $bigtree["config"]["js"]["minify"]
in your /templates/config.php
file to true
. This setting defaults to false.
Variables
Variables are used in JavaScript just like they are used in PHP through the $ indicator. Let's take the following bit of JavaScript as an example:
$.ajax("$www_root" + "ajax/$folder/");
Now, to provide the values to your JavaScript, we will edit /templates/config.php
with the following code (the array should exist in the default config, just add the keys you need).
$bigtree["config"]["js"]["vars"] = array( "folder" => "goose" );
There are two variables that are ALWAYS present and converted: www_root/ and $www_root. You do not have to set these in your configuration file. www_root/ is a convenient way to address your root URL since it always has a / at the end. Take the code from above, modified to use www_root/ instead of $www_root:
$.ajax("www_root/ajax/$folder/");