I am trying to optimize an OpenCart website speed. Unfortunately non of the extensions did any good, so I decided to do everything manually.
I am optimizing the css files for example :
<link href="catalog/view/javascript/jquery/magnific/magnific-popup.css" type="text/css" rel="stylesheet" media="nope!" onload="this.media='all'">
This is working perfectly fine for me, since I build a preloader that waits for all the css to be loaded and then show my page. In that case PageSpeed is happy and I'm happy.
The problem is that the preloader basically works :
<script>
document.onreadystatechange = function() {
if (document.readyState !== "complete") {
document.querySelector(
"body").style.visibility = "hidden";
document.querySelector(
"#loader").style.visibility = "visible";
} else {
document.querySelector(
"#loader").style.display = "none";
document.querySelector(
"body").style.visibility = "visible";
}
};
</script>
This way every time I open the page it shows the loader, and I want to show it only the first time / while the page is still rendering and showing pure html due the the blocking of the css /.
So I am wondering if there is a way to do that..
Thanks in advance!