📜 ⬆️ ⬇️

A small wrapper for several Yandex-Direct blocks on a page with “delayed” loading

Like many webmasters, I am faced with the fact that Yandex-Direct, it happens, slows down when loading. Reason - use

document.write("

, - HTML- “” .

, , - ;-) - FAQ, .

, , - .

“”, -

(/themes/_/theme.php XOOPS/RunCMS, )

function theme_show_context($data) {
if (!isset($data['type'])) {
$data['type'] = 'horizontal';
}

if (!isset($data['limit'])) {
$data['limit'] = 3;
}

if (!isset($data['stat_id'])) {
$data['stat_id'] = 100;
}

$id = md5(serialize($data));


$html = "";

$GLOBALS['yandex_direct'][$id] = $html;
return '<'.'div class="yandex_direct_place" id="'.$id.'">
';
}


but at the very end of the topic, right before the body - that which has accumulated is displayed
')
// calling yandex-direct
foreach ($GLOBALS['yandex_direct'] as $id => $html) {
echo $html;
}

Calling Yandex-Direct code anywhere on the site now looks like this

theme_show_context(array('stat_id' => 10, 'limit' => 2));

Now there is no delay and thinking about the DIV <-> SCRIPT bundle is not necessary.

Source: https://habr.com/ru/post/77347/


All Articles