Optimized my website with WP Rocket and delayed javascript execution with some exclusions. Excluded: /jquery-?0-9.(.min|.slim|.slim.min)?.js and js-(before|after) and my script which has code:
jQuery(document).ready(function() {
console.log('F Loaded');
jQuery('#div_id').bind('click', function() {
jQuery('#desired_element').css('display','block');
console.log('Clicked')
});
});
When I’m loading a website – getting first message in console "F loaded", but after click – action happens only after all rest scripts are loaded. Is there any way to avoid waiting for all other scripts and make that action (style add after click) immediately ? Tried with plain javascript but got same result.
2
Answers
You can use modern way to write click event outside the document ready you will be able to perform click outside document ready.