Deleting a crash page while running jQuery

Users on my site see a half second crash on every page before any jQuery code is executed. This code controls the page so that you can noticeably see how the elements move in one large chunk, which makes the user’s work awkward. I would prefer the page not to display at all until JavaScript starts.

I am using jQuery provided by the Google API on the page as follows:

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
    google.load("jquery", "1.3.2");
</script>
<script type="text/javascript" src="MyScript.js"></script>

In MyScript.js:

google.setOnLoadCallback(runOnLoad);    
function runOnLoad() {
    // Do stuff
}

Does anyone know if JavaScript can be run before the page is displayed in the browser?

+3
source share
2 answers

, css div, , , MyScript.js.

html:

<body>
    <div id="mainContent" class="hidden">
    </div>
</body>

css:

.hidden
{
    display: none;
}

MyScript.js:

$("#mainContent").removeClass("hidden");
+7

.

( ) CSS javascripts. CSS .

0

Source: https://habr.com/ru/post/1719497/


All Articles