V
V
Vadim Timoshenko2020-02-20 11:14:54
1C-Bitrix
Vadim Timoshenko, 2020-02-20 11:14:54

How to leave some js scripts in head?

I use moving all js scripts to the footer (Move all Javascript to the bottom of the page).
But Metrics, Google Analytics, Facebook counters should be in . I tried to just use it in header.php, but it still takes everything to the footer. How to be? How to selectively leave scripts in ? <head>

<script></script><head>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2020-02-20
@PbI6A_KuT

I use moving all js scripts to the footer (Move all Javascript to the bottom of the page).

Remove this checkbox - it's a bad idea. It comes down to processing regular expressions on each hit of the page.

But Metrics, Google Analytics, Facebook counters should be in .

They don't have to, but they want to. It's good for them, it's bad for you. Including because they will count even pages that are not loaded to the end.
I tried to just use it in header.php, but it still takes everything to the basement. How to be? How to selectively leave scripts in ?

As I wrote - remove all the checkboxes, and place the scripts manually.
To display those added through the core, you can use $APPLICATION->ShowHeadScripts();
By placing it in the footer and or in the header, and in the alternative part of the page, simply<script></script>

A
approximate solution, 2020-02-20
@approximate_solution

I use moving all js scripts to the footer (Move all Javascript to the bottom of the page).

What do you carry? Script or plugin? There must be an exception, or a sample. As a rule, it is bad practice to move everything to the footer if there is a lot of content - and you use scripts in the header, there is a chance that if the connection is bad, your scripts will simply not load. Read about asynchronous connection of js scripts. And do not display google speed test in the cargo cult.

S
smilingcheater, 2020-02-21
@smilingcheater

< script data-skip-moving="true" >your script that doesn't need to be moved anywhere</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question