Batman.js is no longer in production at Shopify and is not actively maintained.

This website is left for reference (and for old times' sake).

batman.js

batman.js contains some settings affecting all apps running on the page. These settings are attributes of the global Batman.config object. It's good practice to set these values before defining your app, like so:

Batman.config.pathToHTML = '/templates'
Batman.config.usePushState = false

class MyApp extends Batman.App
  # ...

pathToApp

Default: "/"

Use this if your batman.js app is loaded from a path other than /. For example, if you load your app at /app, you'd use:

  Batman.config.pathToApp = '/app'

Any generated routes will be then be prefixed with /app.

pathToHTML

Default: "/html"

If the app hasn't already loaded the HTML to render a view, it will request the HTML with an AJAX request. pathToHTML is used as the prefix for these requests.

The Batman.rails extra sets Batman.config.pathToHTML= '/assets/batman/html'.

fetchRemoteHTML

Default: true

batman.js automatically fetches a view's HTML if it hasn't been loaded yet. If fetchRemoteHTML is false, an error will be thrown instead.

usePushState

Default: true

Set to false to use batman.js's hashbang navigator instead of the (default) pushState navigator. Note: the pushState navigator automatically degrades to the hashbang navigator if not supported by the browser.

protectFromCSRF

Default: false

Used by the Batman.rails extra. If protectFromCSRF is true, batman.js sends CSRF token as a request header (X-CSRF-Token). batman.js uses metaNameForCSRFToken to find the correct meta tag.

The Batman.rails extra sets Batman.config.protectFromCSRF = true, but you must set it yourself if you're using Rails-style CSRF tokens without the Batman.rails extra.

metaNameForCSRFToken

Default: "csrf-token"

If protectFromCSRF is true, the contents of the meta tag with this name will be used as the CSRF token. This default is set in the Batman.rails extra.

cacheViews

Default: false

If set to true, batman.js will cache Batman.View instances between render calls. View caching is opt-in while its implementation is finalized.

Help us improve our documentation!

Contributions to this page are welcome on Github. If you find a problem but you cannot fix it, please open an issue.

Discussion regarding batman.js documentation is also welcome on our mailing list.