Problem background
I'm developing a web page where users can dynamically change and style a custom horizontal menu. So there's a bunch of style settings (height, padding, etc...) and a preview at the top of the page. When they change these settings, I reload the html for the menu and the css so it has the new values in place.
The problem
As you can see below, i'm loading the html, and once completed, i'm applying the html and reloading the css. This all works. However, there is a split second in most cases where the html flashes without any styling. I believe this is happening while the css is being regenerated. I need to prevent this.
How can I regenerate the stylesheet while preventing the small gap in time when there is no styling?
$.get("http://www.url1.com", function(html) {
// add the new html
$(".preview-section").html(html);
// reload stylesheet
var timestamp = Math.round(+new Date()/1000);
$("head").append($("<link/>", { rel: "stylesheet", href: "http://www.url2.com?cache="+timestamp, type: "text/css" }));
});