Created
November 23, 2012 05:23
-
-
Save rakeshpai/4134122 to your computer and use it in GitHub Desktop.
Closure compiler optimizations
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
// Original | |
var getElementsByTagName = "getElementsByTagName"; | |
var links = document[getElementsByTagName]("link"), | |
anchors = document[getElementsByTagName]("a"), | |
iframeContents = "...<script>var whatever = document." + getElementsByTagName + "('whatever');</script>..."; | |
// becomes | |
var a=document.getElementsByTagName("link"),b=document.getElementsByTagName("a"),c="...<script>var whatever = document.getElementsByTagName('whatever');</script>..."; | |
// whereas, it could become | |
var a="getElementsByTagName",b=document[a]("link"),c=document[a]("a"),d="...<script>var whatever = document."+a+"('whatever');</script>..."; | |
// Granted, I'm doing some code-golfing manually, which isn't a good thing. But the hope was to pass to the compiler some hints about how to optimize further. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment