Intercooler makes AJAX requests to various paths when certain events occur (e.g. A button with a
ic-post-to attribute is clicked, or a polling interval occurs.) and expects a response
of a certain format (typically an HTML fragment). Below we describe both the request and response formats.
Intercooler requests can come take four different forms:
GET- Typically created due to a refresh of an
POST- Created by an element with a
PUT- Created by an element with a
DELETE- Created by an element with a
Because not all browsers support
DELETE requests in AJAX, Intercooler
uses the Rails convention and adds a
_method parameter to the request.
Intercooler requests include a few standard parameters:
ic-request- This will always be
truefor Intercooler-based requests.
ic-last-refresh- This is a timestamp of the last time the target element was refreshed. This can be used to calculate time-sensitive UI updates (e.g. appending to a list of messages.)
ic-fingerprint- The SHA256 fingerprint of the current content. This can be used to avoid sending down unnecessary updates, caching, etc.
Intercooler requests include a few request headers:
Set to the HTTP Method type (e.g.
Also included in the request is the form value of the element that is initiating the request. So, if the element is an input, it will include its name/value in the request. If it is a form, it will include the names/values of all inputs within the form.
You can also include other parameters using the
Intercooler responses are typically HTML fragments. In the typical case, a fragment of HTML will be returned. Here is a simple example of a response body:
<div>Here Is Some Content!<div>
This would be swapped in as the body of the element that initiated the request.
The returned content can contain Intercooler attributes itself, which will be all wired up.
Intercooler interprets an empty body in a request as a No-Op, and will do nothing in response.
To handle these situations, Intercooler responses have at their disposal some custom HTTP headers. These headers can be used to instruct intercooler to perform additional work :
The following Intercooler response headers are available:
||Allows you to trigger a JQuery event handler on the client side|
Allows you to pass JSON data to the event triggered by the
||A comma separated list of dependency paths to refresh.|
||Causes a client-side redirect to the given URL.|
||Cancels any polling associated with the target element.|
||Opens a new window at the given location.|
||Pushes a new location (still in development)|
||Overrides the elements normal transition.|
||Removes the target element.|