How to use lazy_builder to load and replace content asynchronously In my tests, I was able to make content be loaded asynchronous with

function callback_function() {
    sleep(5);
    return ['#markup' =&gt; time()];
}

...

$build['timestamp'] = [
  '#lazy_builder' =&gt; ['callback_function', []],
  '#create_placeholder' =&gt; TRUE,
];


In the case above, drupal renders whatever it wants to render and after the 5 seconds from the sleep it prints the timestamp. So it runs asynchronous.

But when having placeholders attached, it will waits 5 seconds before rendering everything, its not asynchronous. Like the code below:

$build['#markup'] =&gt; 'The timestamp is [timestamp]';
$build['#attached']['placeholders']['[timestamp]'] = [
  '#lazy_builder' =&gt; ['callback_function', []],
  '#create_placeholder' =&gt; TRUE,
];


My ultimate goal is to have for example "The timestamp is 1498827840" and then get it replaced to "The timestamp is 1498827845" after the 5 seconds sleep.
Normally placeholders are used for elements that are not cacheable, like a timestamp, so that the rest of the render array no longer depends on the dynamic data and can be cached. On a cache hit the placeholder gets replaced by the result of the lazy builder. This is the asynchronous part.

What you are trying to do looks more like asynchronous loading of web content in the browser. You can use BipPipe for this, but then don't put a sleep command in the lazy builder, try to solve this in javascript.