The situation
I have been attempting to create a react application. The index page that is loaded first contains a basic CSS and HTML loading animation and then the external scripts and CSS in a blocking order right before </body>
, with the last script removing the loader animation and showing the page.
The intended purpose of this is to load a very small page (2KB
in total) containing a loading animation and then load the 8MB
of scripts, stylesheets and images, creating a more seamless user experience.
<html>
<head>
...
[loader css]
</head>
<body>
<div id="loader">...</div>
<script src="..."></script>
<script src="..."></script>
<link href="..." type="text/css" rel="stylesheet" />
<script> [remove #loader] </script>
</body>
</html>
The problem
This works great in Chrome, as it immediately renders the page (loading animation) and then the external dependencies. But because safari has weird, inconsistent, and ostensibly non-deterministic loading practices:
Safari starts loading the contents of the new web page, but does not start rendering it until it has loaded a sufficient amount of information.
this approach does not work; it'll just show the address bar loading indicator (for the dependencies above the closing body
tag) and a blank page instead of rendering the HTML straight away.
If anybody has a solution that:
- won't change the order in which things are loaded on the page
- works on as many browsers as possible
- is safe from cross-site scripting vulnerabilities
that would be enormously appreciated. Thank you!