V
V
Victoria Erofeeva2020-08-31 20:09:51
1C-Bitrix
Victoria Erofeeva, 2020-08-31 20:09:51

How to make a preloader in Bitrix that starts only on the first visit to the page?

Tell me how to make a preloader in Bitrix, which starts only on the first visit to the page.
I wrote a simple JS code, while the page is loading, the preloader is visible, on the window.onload event (when the entire html has loaded in the browser), JS adds a style to the preloader that hides it.

.loaded {
        display: none;
      }

window.onload = function () {
     const preloader = document.querySelector('.preloader');
      preloader.classList.add('loaded');
     }


It is necessary that on the first visit to the page, while the content is being loaded, the preloader should be loaded, but when you visit the same page again, the preloader should no longer be loaded. How can this be implemented? Check if this page is cached? If this is the main page, where there are both components and static information, how can you check the cache on the side of the PHP code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2020-08-31
@webdefvika

You need to add to the site template a check for the set cookie that is set after the first display and, depending on it, add your code to <head>or not. To do this, you will need the following methods:
https://dev.1c-bitrix.ru/api_d7/bitrix/main/page/a...
https://dev.1c-bitrix.ru/api_d7/bitrix/main/httpre. ..

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question