开发者

Do browsers interpret/execute css tags that they see as empty? (ie IE hacks)

开发者 https://www.devze.com 2023-01-28 06:01 出处:网络
I am curious about the efficiency of this example piece of CSS: ul, a, span,开发者_运维技巧 p, li { *zoom:1; }

I am curious about the efficiency of this example piece of CSS:

ul, a, span,开发者_运维技巧 p, li { *zoom:1; }

Please keep in mind that this is purely theoretical so the merits or pitfalls of CSS hacks are not so much of interest.

My question is — What do browsers other than IE6&7 do:

  1. look to match all the selectors in the page and then realise that it is empty and not act upon it? (horribly inefficient)
  2. Realise it is empty and not act upon the selectors (fairly efficient)
  3. No of the above.

Any ideas would be greatly received.

Cheers, Ad.


I don't know. :) It might depend on the browser, although all of them are in a race to optimize for speed as much as possible. I'd assume they would have thought about this.

But since you can never be sure, I would recommend to put IE hacks inside a separate css file and use conditional comments in HTML to include these css files conditionally.

But when doing that, I think you should also provide these files with an 'Expires' header that allows them to be cached for a longer period of time (like a day?). When you don't provide these headers, IE will invalidate the cached file much sooner than most other browsers, which might cause more requests (for these separate css files) to your server when a visitor is browser multiple pages of your site. Usually this will not be a big problem, but if you're talking optimization like this, it might be an issue.


Assuming a browser obeys the specification, it will simply ignore the *zoom property:

User agents must ignore a declaration with an unknown property. For example, if the style sheet is:

h1 { color: red; rotation: 70minutes }

the user agent will treat this as if the style sheet had been

h1 { color: red }

As for what happens if such a browser finds an empty declaration block, I don't know. I haven't seen the scenario mentioned in the spec, so I would guess it's an implementation detail and it'd differ browser by browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消