Skip to content

Instantly share code, notes, and snippets.

@rakeshpai
Created November 23, 2012 05:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rakeshpai/4134122 to your computer and use it in GitHub Desktop.
Save rakeshpai/4134122 to your computer and use it in GitHub Desktop.
Closure compiler optimizations
// 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