The posted code from (@carlosatfongo) helped our website a lot by fixing the endless loading issue in Firefox. However, there was still an annoying flashing of the website before the preloader (The problem in Firefox is, reload > flash website > preloader > website visual).
To prevent this blinking and to find an even more reliable solution, I developed the following code for functions.php:
add_action('wp_footer', function() {
?>
<script>
(function($) {
// Check if it is the Firefox browser
var isFirefox = typeof InstallTrigger !== 'undefined';
if (isFirefox) {
// Add a class to hide the website
$('body').addClass('hidden-site');
// Remove the class after a fixed delay before the page is fully loaded
setTimeout(function() {
// Remove the class to show the page
$('body').removeClass('hidden-site');
}, 500); // Change the delay time here as needed (in milliseconds)
}
})(jQuery);
</script>
<?php
});
This code should be placed below the code provided by (@carlosatfongo). The success of this solution was particularly evident when used in conjunction with Dark Mode.
The code couldn’t be effectively combined into a single action because the two actions need to be executed separately within wp_footer, which helps reduce timing conflicts. First, the preloader is hidden, and then the website’s visibility is controlled based on the browser type. This approach minimizes the likelihood of timing-related issues.
Thanks to (@carlosatfongo) for the original code, and thanks to everyone for the support and solution finding.