Answer the question
In order to leave comments, you need to log in
What options for asynchronous loading can be used with inline js code?
Good day,
I have a specific question, I have been optimizing the speed of sites for a long time, but I could not cope with one problem, the situation is very standard, a WordPress template and a few plugins (at the moment there is a problem with the Revolution slider).
jQuery is loaded asynchronously (async / defer) from the server itself or cdn (not so important),
code example
<script defer src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script>
$( document ).ready(function() {
console.log( "ready!" );
});
</script>
function jQueryWaiting() {
if (typeof jQuery === "undefined") {
setTimeout(jQueryWaiting,100);
return;
}
$(document).ready(function(){
console.log( "ready!" );
});
}
jQueryWaiting();
Answer the question
In order to leave comments, you need to log in
If you are concerned about speed and optimization, then shouldn't all scripts be concatenated in the order you need, minified, and then just load 1 file? The code from any tutorial about gulp\grunt will solve this problem with a bang.
Or wrap the initialization of the slider in(function ($) { //init slider here})(jQuery);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question