Include Craft JS object In the controller documentation for plugins, there's a section that talks about routing to specific actions using a Craft object like this:

var url = Craft.getActionUrl('cocktailRecipes/ingredients/saveIngredient', { id: 10 });


I think this object is the one in /craft/app/resources/js/craft.js, but I can't figure out how to make it available. I tried including it via includeJsResource, but this doesn't appear to be working

{% includeJsResource "resources/js/craft.js" %}


What do I need to include to be able to use this object in my JavaScript (it is not a load ordering issue, the URL generated by includeJsResource goes to the 404 page)?
The Craft global variable is available to any Javascript running in the backend/Control Panel, without including anything.

It's not possible to include, reference or use the global for any code running in the frontend.



EDIT:

To provide access to a controller action for frontend Javascript, I'd recommend setting up a site route in your plugin's main class. The following will route the URL http://yourbaseurl/myplugin/foobar/add to ExampleController:

public function registerSiteRoutes()
{
    return array(
        'myplugin/foobar/add' =&gt; array('action' =&gt; 'myPlugin/example/add'),
    );
}


As for the ExampleController, be sure to set the $allowAnonymous class variable to true. This allows visitors that aren't logged in to Craft access (beware that this will make all your controller´s actions accessible without login):

class MyPlugin_ExampleController extends BaseController
{
   protected $allowAnonymous = true;
   public function actionAdd()
   {
       // Your code here           
   }
}