<ajax:delayedload>
AJAX
ATTRIBUTES
EXAMPLES
Data
Forms
Layout
Logic
Navigation
Personalisation
Standard
Templates
Regions
Third Party

<ajax:delayedload> </...>

Delayed load regions can improve the server processing time of a page.

It works by ignoring the contents of this tag in the initial page load.
The contents are then loaded via a second AJAX request after everything else.

The main use case is to make secure server-side API requests without affecting performance.
For instance: loading data from an external feed, then presenting it in a repeater.

The AJAX request and this library's code makes the total download size of your page larger, so use of this control is recommended only to defer server processing time.

Content

any
The content to load later.

Attributes

id
string
(Required) Give this control a unique id. Can be accessed in the client DOM (eg, document.getElementById('myid') or in the server DOM using [? $myid ?] or [? $('myid') ?]).
test
bool
Only delays the load if the test evaluates to false.

Can be used with Caching to prevent delaying loads when a cache exists.
Eg: test="[? \Framework\Caching::isCached('xyz') ?]"

Examples

Currency Feed

Pulls a JSON currency feed and displays the results

HTML:

<h3>Live Currency Rates Will Appear Below</h3> <ajax:delayedload id="delayedload_region"> <data:table datasource="downloadRates()" as="rate" emptymessage="Could not download rates"> <data:column heading="Currency"> [? $rate['code'] ?] </data:column> <data:column heading="Rate"> [? round($rate['rate'], 2) ?] </data:column> </data:table> </ajax:delayedload> <p><a href="#" onclick="window.location.reload(); return false;">Refresh example.</a></p>

PHP:

<?php function downloadRates() { $sJSON = @makeHTTPRequest('http://www.floatrates.com/daily/usd.json'); if (!$sJSON) return []; $arrJSON = @json_decode($sJSON, true); return $arrJSON ?? []; } ?>

Run Example

Sleep

Demonstrates a long running operation through calling PHP's sleep() function.

HTML:

<p>This content loads first.</p> <ajax:delayedload id="delayedload_region"> <div> [? someLongRunningProcess() ?] <p>Before this content which took 3 seconds to process on the server.</p> </div> </ajax:delayedload> <p>This content also loads first.</p> <p><a href="#" onclick="window.location.reload(); return false;">Refresh example.</a></p>

PHP:

<?php function someLongRunningProcess() { sleep(3); } ?>

Run Example