Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Performance Improvement and IE7 Bug Fix #35

Closed
wants to merge 4 commits into
from
View
@@ -17,6 +17,7 @@
docElem = doc.documentElement,
mediastyles = [],
rules = [],
+ currentIds = "",
appendedEls = [],
parsedSheets = {},
resizeThrottle = 30,
@@ -137,9 +138,9 @@
docElemProp = docElem[ name ],
currWidth = doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
styleBlocks = {},
- dFrag = doc.createDocumentFragment(),
lastLink = links[ links.length-1 ],
- now = (new Date()).getTime();
+ now = (new Date()).getTime(),
+ newIds = [];
//throttle resize calls
if( fromResize && lastCall && now - lastCall < resizeThrottle ){
@@ -151,18 +152,28 @@
lastCall = now;
}
- for( var i in mediastyles ){
+ for( var i = 0; i < mediastyles.length; i++ ){
var thisstyle = mediastyles[ i ];
if( !thisstyle.minw && !thisstyle.maxw ||
( !thisstyle.minw || thisstyle.minw && currWidth >= thisstyle.minw ) &&
(!thisstyle.maxw || thisstyle.maxw && currWidth <= thisstyle.maxw ) ){
if( !styleBlocks[ thisstyle.media ] ){
styleBlocks[ thisstyle.media ] = [];
}
+ newIds.push( i );
styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
}
}
+ //skip if nothing has changed
+ newIds = newIds.join("-");
+ if( newIds === currentIds ) {
+ return;
+ }
+ else {
+ currentIds = newIds;
+ }
+
//remove any existing respond style element(s)
for( var i in appendedEls ){
if( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){
@@ -177,19 +188,18 @@
ss.type = "text/css";
ss.media = i;
+
+ //append to DOM first for IE7
+ head.insertBefore( ss, lastLink.nextSibling );
if ( ss.styleSheet ){
ss.styleSheet.cssText = css;
}
else {
ss.appendChild( doc.createTextNode( css ) );
}
- dFrag.appendChild( ss );
appendedEls.push( ss );
}
-
- //append to DOM at once
- head.insertBefore( dFrag, lastLink.nextSibling );
},
//tweaked Ajax functions from Quirksmode
ajax = function( url, callback ) {
@@ -213,8 +223,8 @@
xmlHttp = (function() {
var xmlhttpmethod = false,
attempts = [
- function(){ return new ActiveXObject("Microsoft.XMLHTTP") },
- function(){ return new XMLHttpRequest() }
+ function(){ return new XMLHttpRequest() },
+ function(){ return new ActiveXObject("Microsoft.XMLHTTP") }
@scottjehl

scottjehl Jun 29, 2011

Owner

Can you explain this change? The loop below goes in reverse, so the former order would hit the standards-based model first...

@dvelyk

dvelyk Jun 30, 2011

Hi! I'm afraid I can't really explain this change.. I hadn't intended this to be a part of my pull request, actually. I'm new to github ;) All I can tell you is that before I made the change, IE8 tabs were crashing (the "Can't use in IE8" issue -- #27), and switching the order put an end to that. At least, a couple days ago. Now I can't crash IE8 no matter what I do, and the order of these functions seems to make no difference at all. I don't think I've significantly changed anything in that time, so I'm not sure what the deal is.

Feel free to leave these lines out, or let me know if I need to remove the commit from my copy before you pull in the other changes. If IE8 starts crashing on me again I'll do some further experimenting to confirm if the XMLHttpRequest object is the culprit or not.

],
al = attempts.length;