Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What might cause CSS to fail to load occasionally on all browsers?

Tags:

css

tomcat

I'm working on a webapp, and every so often we run into situations where pages will load without applying CSS. This problem has shown up in IE6, IE7, Safari 3, and FF3.

A page refresh will always fix the problem.

There are 3 CSS files loaded, all within the same style block using @import:

<STYLE type="text/css">
  @import url([base css file]);
  @import url([skin css file]);
  @import url([generated css path]);
</STYLE>

In any situation when we take the time to examine the html source, nothing is out of the ordinary. Access logs seem normal as well - we're getting HTTP 304 responses for the static CSS files whenever they are requested, and an HTTP 200 response for our generated CSS.

The mimetype is text/css for the css files and the generated css. We're using an iPlanet server, which forwards requests to a Tomcat server.

davebug asked:

Is it always the same css file not loading, or is the problem with all of them, evenly?

None of the CSS files load. Any styles defined within the HTML work fine, but nothing in any of the CSS files works when this happens.

like image 524
Illandril Avatar asked Sep 18 '08 16:09

Illandril


People also ask

Why does CSS not work sometimes?

If you put the <link> tag inside another valid header tag like <title> or <script> tag, then the CSS won't work. The external style CAN be put inside the <body> tag, although it's recommended to put it in the <head> tag to load the style before the page content.

Why is website CSS not loading?

A site may not load the CSS file due to browser caching. It's the most common cause and is the easiest to fix because you only need to remove the cache from your browser. Yet, there are times when an invalid line of code or conflict with other themes and plugins can also make the CSS file unreadable.

Why is my CSS not working in Chrome?

Correct CSS encoding and format (for designers) Whether it is from a CMS like WordPress or your custom-built website, Chrome will not load CSS properly for a reason. If your HTML and CSS are not in the same encoding format, you will see broken styling in web pages on Chrome. So, make sure formats are the same for both.


1 Answers

I've had a similar thing happen that I was able to fix by including a base style sheet first using the "link rel" method rather than "@import". i.e. move your [base css file] inclusion to:

<link rel="stylesheet" href="[base css file]" type="text/css" media="screen" />

and put it before the others.

like image 128
da5id Avatar answered Oct 01 '22 00:10

da5id