Created
December 18, 2013 20:19
-
-
Save tkissing/8029250 to your computer and use it in GitHub Desktop.
Console script to count and list out globals on your page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint browser:true, eqeq:true, forin:true, sloppy: true*/ | |
(function (window, document) { | |
var differences = {}, | |
exceptions = ['addEventListener', 'document', 'location', 'navigator', 'window'], | |
globals = [], | |
ignoreList = (window.prompt('Ignore filter (comma sep)?', '$,jQuery,ko') || '').split(','), | |
iframe = document.createElement('iframe'), | |
i; | |
for (i in window) { | |
if (exceptions.indexOf(i) < 0 && ignoreList.indexOf(i) < 0 && (String(window[i]) != '[object Window]')) { | |
differences[i] = { | |
'type': typeof window[i], | |
'val': window[i] | |
}; | |
} | |
} | |
iframe.style.display = 'none'; | |
document.body.appendChild(iframe); | |
iframe.src = 'about:blank'; | |
iframe = iframe.contentWindow || iframe.contentDocument; | |
for (i in differences) { | |
if (iframe[i] === undefined) { | |
globals.push(i); | |
} | |
} | |
window.console.log('You have these %s globals', globals.length, globals); | |
}(window, window.document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment