I'm currently implementing some embed widgets that people can insert into their websites. These blocks need CSS to give format to the HTML.
I'm including the stylesheets by appending the link tag in the head of the document but this only guarantee that the browser will start retrieving the stylesheet.
My problem is not about performance, my problem is that HTML loads before the stylesheet is downloaded and is shown with the default styles until browser downloads the stylesheet (sometimes this can take seconds if the connection is low, like mobile connections).
How can I control the moment when the stylesheet is downloaded and parsed? My aim is to hide content and show it when the stylesheet is totally loaded. The ideal way would be a callback function.
Thanks in advance.
Notes: I need something like async loading of images. Javascript allows loading images asynchronously with a callback function when is completely downloaded so you can show a loading spinner or hide it until is totally loaded.