Browser displays page without styles for a short moment (visual glitch)

自古美人都是妖i 提交于 2019-12-01 10:11:27

This is called a FOUC, a Flash Of Unstyled Content, and is well documented and explained here: http://www.bluerobot.com/web/css/fouc.asp/

I did not have the problem, usually has to do with internet connection. CSS loading slowly.

FOUC has to do with the order of loading external assets like CSS and JS files. Inline script snippets block downloading of subsequent assets until they are interpreted. This is one of the causes for FOUC.

A best-practice for front-end performance as well as avoiding FOUC is to have your CSS files referenced in the <head> of your document and your JavaScript right before the closing </body> tag.

This makes the browser download styles, render the page, then apply JavaScript.

I was having this same problem. I simply switched the order in which stylesheets and javascript were getting loaded in the head of layouts/application.html.erb. So now the stylesheets get loaded first and then the javascript.

Like so:

<head>
 <title><%= full_title yield(:title) %></title>
 <%= stylesheet_link_tag    :application, media: "all" %>       
 <%= javascript_include_tag :application %>       
 <%= csrf_meta_tags %>
</head>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!