Internet Explorer limits nested @import CSS statements

I have been lately working on a collection of home-made widgets based on Dojo. This architecture has been designed to reuse elements and so there are widgets inside widgets, the code is arranged and structured, CSS is imported in a waterfall model, and everything should be fine and working properly.

Until Internet Explorer.

Let’s not talk about its mystic JavaScript errors, DOM random model interpretations and box model hacks. I had heard about the 32 @import CSS statements limit before (here, here and here), but what we were experiencing was different: beyond a given number of nested CSS imports, it seemed like stylesheets stopped being loaded. This was a big WTF the first time we spotted the problem, and blindly fixed it by adding twice the deeper @import sentences into the higher level CSS files. After all, it worked then.

But after a bad night of guilty conscience that issue came back to me, and I decided to do some tests on the issue so that some light be thrown on this dark matter. This was the plan: a simple HTML file with a number of divs (with a border and height definitions to make them visible by default), and a set of CSS files that where imported in waterfall mode, each one of them assigning the background color of one div according to its nesting level. The rupture point would be spotted where div’s started to look blank. Something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<html>
	<head>
		<link type="text/css" rel="stylesheet" href="style01.css" />
	</head>
	<style type="text/css">
		body div{
			height: 30px;
			margin: 5px;
			border: 1px solid #000;
		}
	</style>
	<body>
		<div class="style01"></div>
		<div class="style02"></div>
		<div class="style03"></div>
		<div class="style04"></div>
		<div class="style05"></div>
		<div class="style06"></div>
		<div class="style07"></div>
		<div class="style08"></div>
		<div class="style09"></div>
		<div class="style10"></div>
	</body>
</html>

The CSS files would look all like this one (style01.css):

1
2
3
4
5
@import url("style02.css");
 
.style01{
	background: #111;	
}

And so on (style02.css, etc):

1
2
3
4
5
@import url("style03.css");
 
.style02{
	background: #222;	
}

And up to 10 nested levels, in my test. What the result was? Every major modern browser (Firefox, Chrome, Opera, Safari) produced the expected result:

Results of the CSS test for all major modern browsers

On the contrary, under Internet Explorer 8 and, moreover, 9, the result matched the little ‘panic moment’ we had when dealing with our nested collection of widgets:

Which actually confirmed that Internet Explorer limits nested @import CSS statements to three from the first linked external stylesheet. In the example, up to style04.css. In a production environment this is not a big deal since all CSS files are going to be packed into a single minified and compressed bundle, but it really can piss your day off in development environments should you not be aware of this behavior.

Once again, a reason to make me think of IE as a bad joke of a real browser.

One thought on “Internet Explorer limits nested @import CSS statements

Leave a Reply

Your email address will not be published. Required fields are marked *