FIT can be used to deliver only fragments instead of complete HTML documents. This can be useful for AJAX requests, with other frameworks instead of Partial Page Loading. For this to work, the fragment has to be marked explicitly.
By default FIT parses all content it receives as a complete document. The fragment:
<div>foobar</div>
will be parsed to the following document:
<!DOCTYPE html>
<html>
<head/>
<body>
<div>foobar</div>
</body>
</html>
This document will be processed by FIT. URLs will be rewritten, ACs will be processed and FIT JavaScript will be added. That way a simple response for a few elements is a lot bigger (several KB depending on the enabled features) than it needs to be and contains additional JavaScript elements that may result in client side errors upon insertion into the document.
Using fragments the resulting response is smaller and contains no interfering JavaScript.
To make sure all FIT features work after a fragment request, all enabled features used in the fragment must already be present in the client (e.g. do not enable the Delivery Context API in the flow.xml only for the fragment request).
We stronlgy recommend registering ACs unconditionally if fragment handling is enabled.
Delayed Images should be deactivated for fragment requests. Alternatively you have to initiate the loading of Delayed Images yourself after the content is inserted in your document.
FIT automatically disables Delayed Images if the Delivery Context property request/fragment
is set to true
. This property is set automatically when using the ;m=fragment
URLMark or can be set manually with the set-dc Action.
Note: Be careful when using the register-xslt Action on fragment requests. This action can result in faulty behaviour of some FIT features, especially Adaptive Components.
To send only the desired content via FIT, it has to be enclosed in <ai-document-fragment>
elements. Everything but the child elements of these document fragments are filtered before transporting the content to the client.
This feature cannot be enabled or disabled in the config.xml
file. It will be used every time the document contains an <ai-document-fragment>
element.
The markers are set automatically by FIT for the whole requested content if the request is sent with a certain URLMark.
The markers can also be inserted by hand using XSL or already be included in the requested document.
In automatic fragment mode, FIT automatically adds <ai-document-fragment>
elements around the document fragment received from the backend during the Parse Action. It is triggered if
;m=fragment
is set, orcontent-handling/retain-html-fragments
is enabled, the resource is sent with a proper HTML Content-Type response header, and contains fragment HTML markup unless the first start tag is one of the following tags: html
, head
, base
, link
, meta
, script
, style
, title
.Setting the URLMark ;m=fragment
can be achieved by setting the role of an URL to role="fragment"
.
<a href="foo.html" ai-url-role="fragment">foobar</a>
The JavaScript URL API does not support setting roles for URLs, but the URLMark can be set explicitly with ai.urls.composeUrl
.
ai.urls.composeUrl('foo.html', [{name: 'm', value: 'fragment'}]);
After the normal processing of the document is done, only the content between <ai-document-fragment>
elements is sent to the client.
In automatic fragment mode, the Delivery Context property request/fragment
is set to true
. In the second case (with option content-handling/retain-html-fragments
enabled), this is true
only after the parsing of the response.
Warning: The <ai-document-fragment>
markers are inserted when the Parse Action is executed. If a xslt Action has already run, the document fragment received from the backend is already parsed when the Parse Action is executed and the markers cannot be inserted correctly.
Content received from backend:
<div id="foo">
A
B
</div>
<div id="bar">
<h1>foo bar</h1>
<p>
<span>ABC</span>
<span>DEF</span>
</p>
</div>
<ac-stage id="foobar">
[...]
</ac-stage>
Document after Parse Action:
<html>
<head/>
<body>
<ai-document-fragment>
<div id="foo">
A
B
</div>
<div id="bar">
<h1>foo bar</h1>
<p>
<span>ABC</span>
<span>DEF</span>
</p>
</div>
<ac-stage id="foobar">
[...]
</ac-stage>
</ai-document-fragment>
</body>
</html>
Result sent to the client:
<div id="foo">
A
B
</div>
<div id="bar">
<h1>foo bar</h1>
<p>
<span>ABC</span>
<span>DEF</span>
</p>
</div>
<div id="foobar" class="AC_stage">
[...]
</div>
<script id="AC_stage_stageInit_foobar">...</script>
Alternatively the <ai-document-fragment>
elements can be set via xslt Action or already contained in the received content. This way it is also possible to have more than one <ai-document-fragment>
in the document.
The content of multiple <ai-document-fragment>
elements is simply concatenated in the output.
The document before processing:
<html>
<head>
<title>foo</title>
</head>
<body>
A
B
<ai-document-fragment>
Fragment 1
<span>Y</span>
Z
</ai-document-fragment>
<div>
<p>
<ai-document-fragment>
Fragment 2
<span>foobar</span>
</ai-document-fragment>
</p>
</div>
C
D
<ai-document-fragment>
Fragment 3
1
2
</ai-document-fragment>
E
F
</body>
</html>
Result sent to the client:
Fragment 1
<span>Y</span>
Z
Fragment 2
<span>foobar</span>
Fragment 3
1
2
request/fragment
The Delivery Context property request/fragment
is automatically set to true
if the URLMark ;m=fragment
is used. You should consider setting it to true
with set-dc Action when you insert <ai-document-fragment>
elements manually.
<flow>
...
<set-dc property="request/fragment" xpath="true()" />
...
</flow>
If request/fragment
is set to true
, only Delayed Images with ai-priority="visibility"
are used for the request.
Some points to keep in mind while using fragments:
;m=fragment
URLMark, you should not use a xslt Action on the requested content before using the Parse Action. Otherwise the <ai-document-fragment>
markers cannot be inserted correctly.request/fragment
is set to true
(either because of the ;m=fragment
URLMark or set using the set-dc Action), FIT automatically disables Delayed Images whose ai-priority
attribute are not set to visibility
.responseText
will be available, not responseXML
.flow.xml
only for the fragment request.Particular attention has to be paid when using fragments together with AC Stages.
stageinit
Events are fired once for each fragment containing one or multiple AC Stages.