Answer the question
In order to leave comments, you need to log in
How to remove Bitrix core system scripts from the page body?
Good afternoon.
I noticed that the script "/bitrix/js/main/core/core.js" is displayed in the body of the page - help, how to remove it?
There is a feeling that this is the core and it is displayed through <?$APPLICATION->ShowHead();?>
Are there any simple ways?
Answer the question
In order to leave comments, you need to log in
Actually it is, calling <?$APPLICATION->ShowHead();?> is equivalent to
<?
$APPLICATION->ShowMeta('keywords');
$APPLICATION->ShowMeta('description');
$APPLICATION->ShowHeadStrings();
$APPLICATION->ShowHeadScripts();
$APPLICATION->ShowCSS();
?>
If you don’t like Bitrix scripts at all, then you can cut them out once and for all with a regular
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('main', 'OnEndBufferContent', 'deleteKernelScripts');
function deleteKernelScripts(&$content)
{
global $USER;
if (defined("ADMIN_SECTION")) {
return;
}
if (is_object($USER) && $USER->IsAuthorized()) {
$arPatternsToRemove = [
'/<script[^>]+?>var _ba = _ba[^<]+<\/script>/',
];
} else {
$arPatternsToRemove = [
'/<script.+?src=".+?js\/main\/core\/.+?(\.min|)\.js\?\d+"><\/script\>/',
'/<script.+?src="\/bitrix\/js\/.+?(\.min|)\.js\?\d+"><\/script\>/',
'/<link.+?href="\/bitrix\/js\/.+?(\.min|)\.css\?\d+".+?>/',
'/<link.+?href="\/bitrix\/components\/.+?(\.min|)\.css\?\d+".+?>/',
'/<script.+?src="\/bitrix\/.+?kernel_main.+?(\.min|)\.js\?\d+"><\/script\>/',
'/<link.+?href=".+?kernel_main\/kernel_main(\.min|)\.css\?\d+"[^>]+>/',
'/<link.+?href=".+?main\/popup(\.min|)\.css\?\d+"[^>]+>/',
'/<script.+?>BX\.(setCSSList|setJSList)\(\[.+?\]\).*?<\/script>/',
'/<script.+?>if\(\!window\.BX\)window\.BX.+?<\/script>/',
'/<script[^>]+?>\(window\.BX\|\|top\.BX\)\.message[^<]+<\/script>/',
'/<script[^>]+?>var _ba = _ba[^<]+<\/script>/',
'/<script[^>]+?>.+?bx-core.*?<\/script>/'
];
}
$content = preg_replace($arPatternsToRemove, "", $content);
$content = preg_replace("/\n{2,}/", "\n", $content);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question