Change back to sync stylesheets to prevent FOUC in Firefox & Chrome

This commit is contained in:
Sami Samhuri 2019-12-31 15:42:23 -08:00
parent da56d10818
commit eb90c07585
2 changed files with 6 additions and 21 deletions

View file

@ -24,23 +24,6 @@ extension Node where Context == HTML.HeadContext {
}
}
extension Node where Context == HTML.BodyContext {
static func asyncStylesheetLinks(_ urls: [URLRepresentable]) -> Self {
.script("""
(function() {
var urls = [\(urls.map { "'\($0)'" }.joined(separator: ", "))];
urls.forEach(function(url) {
var css = document.createElement('link');
css.href = url;
css.rel = 'stylesheet';
css.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(css);
});
})();
""")
}
}
extension Node where Context == HTML.BodyContext {
static func time(_ nodes: Node<HTML.BodyContext>...) -> Self {
.element(named: "time", nodes: nodes)

View file

@ -10,7 +10,8 @@ import Plot
enum Template {
static func site(body: Node<HTML.BodyContext>, context: TemplateContext) -> HTML {
HTML(.lang("en"),
HTML(
.lang("en"),
.comment("meow"),
.head(
.encoding(.utf8),
@ -30,7 +31,10 @@ enum Template {
.meta(.name("theme-color"), .content("#ffffff")),
.link(.rel(.dnsPrefetch), .href("https://use.typekit.net")),
.link(.rel(.dnsPrefetch), .href("https://netdna.bootstrapcdn.com")),
.link(.rel(.dnsPrefetch), .href("https://gist.github.com"))
.link(.rel(.dnsPrefetch), .href("https://gist.github.com")),
.group(context.styles.map { url in
.link(.rel(.stylesheet), .type("text/css"), .href(url))
})
),
.body(
.header(.class("primary"),
@ -60,8 +64,6 @@ enum Template {
.a(.href(context.url(for: "about")), .text(context.site.author))
),
.asyncStylesheetLinks(context.styles),
.group(context.scripts.map { script in
.script(.attribute(named: "defer"), .src(script))
}),