Answer the question
In order to leave comments, you need to log in
Is it possible to delay the execution of inline scripts?
Subject.
Is there a way to force the browser to skip inline scripts on page load and execute them later on some event?
UPD: The
question is exactly what it asks - is it possible to force the browser to delay the execution of inline scripts.
I know that there are events and scripts can be hung on them.
I know that it is possible to take out scripts in a file.
I know that they can be loaded at the end of the page.
I know how to asynchronously load and synchronously execute scripts in the right order.
It's all great. But unfortunately, I noticed that besides me, someone else makes websites on the Internet. Moreover, I have neither FTP nor SSH access to some sites and I cannot interfere with the structure of their pages. Such is the misfortune.
UPD2:
Let's take a site on Bitrix. with standard templates. They contain a lot of inline code that uses the functions of the BX library.
It is usually loaded at the very beginning. Google will swear at the scripts at the beginning of the document. But there is no way to take this bible to the end - it must be loaded earlier than inline scripts. You can't load it asynchronously either - it's not a fact that it will have time to load and execute before inline scripts.
The client does not have the means to rewrite all the templates. But he wants a nosebleed with high scores in the page analyzer in Google.
The only variant to achieve this somehow is to force the browser to postpone the execution of inline scripts altogether until the bible is loaded and executed.
(I’m lying of course - not the only one, you can insert the bible itself as an inline script, then Google doesn’t swear, and that’s exactly what I solved the problem, but it’s a complete crap)
Answer the question
In order to leave comments, you need to log in
There is an event onload - full loading of the page. Move scripts there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question