diff --git a/app/views/layouts/_asset_reconciliation.html.erb b/app/views/layouts/_asset_reconciliation.html.erb index 58b08f95c..1ce4d9012 100644 --- a/app/views/layouts/_asset_reconciliation.html.erb +++ b/app/views/layouts/_asset_reconciliation.html.erb @@ -20,30 +20,29 @@ var pageCrayons = document.querySelector("meta[name='proper-stylesheet-crayons']"); var pageViews = document.querySelector("meta[name='proper-stylesheet-views']"); var pageMinimal = document.querySelector("meta[name='proper-stylesheet-minimal']"); - if (headCacheCheck && headCrayons && // If these elements exist, we can proceed. parseInt(pageCacheCheck.content) > parseInt(headCacheCheck.content) && // If page cached-at is larger than head cached-at (pageCrayons.content != headCrayons.href || // If the head-cached values do not match page-cached, we replace pageViews.content != headViews.href || pageMinimal.content != headMinimal.href) ) { - var head = document.head; + var docBody = document.body; // Add new stylesheets if we deem we should. var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = pageCrayons.content; - head.appendChild(link); + docBody.appendChild(link); var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = pageViews.content; - head.appendChild(link); + docBody.appendChild(link); var link = document.createElement("link"); link.type = "text/css"; link.rel = "stylesheet"; link.href = pageMinimal.content; - head.appendChild(link); + docBody.appendChild(link); // Take a breath and then remove the old ones. // If we call this immediately it could cause a flash of unstyled comments. diff --git a/app/views/layouts/_styles.html.erb b/app/views/layouts/_styles.html.erb index 50e0d6892..73fcdc7e5 100644 --- a/app/views/layouts/_styles.html.erb +++ b/app/views/layouts/_styles.html.erb @@ -1,9 +1,3 @@ -<%# We used to inline a good majority of our CSS %> -<%# We are currently testing a simpler method of just using "traditional" render-blocking CSS %> -<%# The trade-off is the potential to render without blocking the page %> -<%# But if we in-line everything we lose the ability to cache assets for repeat visitors %> -<%# This is a production test to see how this might affect UX and/or SEO %> - -<%= stylesheet_link_tag "crayons", media: "all", id: "main-crayons-stylesheet" %> -<%= stylesheet_link_tag "views", media: "all", id: "main-views-stylesheet" %> -<%= stylesheet_link_tag "minimal", media: "all", id: "main-minimal-stylesheet" %> +<%= stylesheet_link_tag "crayons", media: "all", id: "#{qualifier}-crayons-stylesheet" %> +<%= stylesheet_link_tag "views", media: "all", id: "#{qualifier}-views-stylesheet" %> +<%= stylesheet_link_tag "minimal", media: "all", id: "#{qualifier}-minimal-stylesheet" %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 9388d6990..275fb791b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,7 +22,9 @@ <% end %> <%= yield %> - <%= render "layouts/asset_reconciliation" %> + <% if user_signed_in? %> + <%= render "layouts/asset_reconciliation" %> + <% end %> <%= render "shell/bottom" %> diff --git a/app/views/shell/_top.html.erb b/app/views/shell/_top.html.erb index 0395e8816..a30c2c63f 100644 --- a/app/views/shell/_top.html.erb +++ b/app/views/shell/_top.html.erb @@ -17,14 +17,7 @@ <% end %> - <%= render "layouts/styles" %> - + <%= render "layouts/styles", qualifier: "main" %> <% unless user_signed_in? %> <%= javascript_packs_with_chunks_tag "base", "Search", defer: true %> <% end %> @@ -63,6 +56,8 @@ data-deployed-at="<%= ForemInstance.deployed_at %>" data-latest-commit-id="<%= ForemInstance.latest_commit_id %>" data-ga-tracking="<%= SiteConfig.ga_tracking_id %>"> + <%# Repeat of stylesheets in to fix rendering glitch: https://github.com/forem/forem/issues/12377 %> + <%= render "layouts/styles", qualifier: "secondary" %>