IE8 doesn't parse mediaqueries when looking at www variant of a site #20

Reggino opened this Issue May 9, 2011 · 6 comments


None yet

4 participants


When you're on the script thinks all the stylesheets are already parsed. All non-www domains work fine. I think the problem sits in the regular expression used on line 45 of the script.

When I replace that regular expression with this one everything works again on IE8:


Same problem occurred for me. Works when replacing the regexp with the one posted by @Kingsquare


hmm okay. I'll take a look, thanks so much!


Another “fix” is to use relative URLs in the HTML. In that case you can just replace sheet.href on line 37 with sheet.getAttribute('href'), which will return the non-normalized attribute value in IE8.


Thanks @mathiasbynens. I'd like it to work with abs urls too though... did you happen to try the above suggestion? I haven't had a chance to test it yet.


Yeah, that works.

It took some time to figure this out, so let me just write this down :) The reason the current regex fails is this:

if( !/^([a-zA-Z]+?:(\/\/)?(www\.)?)/.test( href ) 
|| href.replace( RegExp.$1, "" ).split( "/" )[0] === ) {}

The regex basically checks if it’s an absolute URL, and if it is, it verifies it’s on the same domain as the current page.
Since the regex includes the www. however, RegExp.$1 will equal e.g. http://www., so that entire portion (including the www.) will be removed before comparing it to Of course, '' != '', so the if check will fail.

IE8 normalizes sheet.href so it’s the full resolved URL, while IE7 doesn’t. (Hence my previous comment.) That’s why IE7 doesn’t have the problem as long as relative URLs are used in the HTML. If absolute URLs are used, IE7 will have the same issue.


I read that 6 times, and on the 6th time, it finally made sense. :)

@scottjehl scottjehl closed this in 23f4db3 Jun 10, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment