S
S
Sergey2020-12-07 20:37:08
1C-Bitrix
Sergey, 2020-12-07 20:37:08

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

2 answer(s)
P
PetrPo, 2020-12-07
@PetrPo

Actually it is, calling <?$APPLICATION->ShowHead();?> is equivalent to

<?
$APPLICATION->ShowMeta('keywords');
$APPLICATION->ShowMeta('description');
$APPLICATION->ShowHeadStrings();
$APPLICATION->ShowHeadScripts();
$APPLICATION->ShowCSS();
?>

$APPLICATION->ShowHeadStrings(); - somewhere there this same core.js is connected. But if you do not have a call to \CJSCore::Init(), then the core itself will not be connected, which means that you have some bitrix js libraries connected and apparently they are needed)
) at least bitrix ajax will not work (component parameter AJAX_MODE), and since this ajax is wired in the core and is available in absolutely all components, then this can bring big trouble

A
Alexey, 2020-12-08
@alexprowars

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 question

Ask a Question

731 491 924 answers to any question