I have a JavaScript application that generates a significant amount of DOM elements. It means that I often use document.createElement("tagname")
in my script.
I am thinking about using this simple function:
function c(e) {return document.createElement(e);}
I would keep writing my code in JavaScript (or maybe CoffeScript), and use the full document.createElement method in the code for readability. But I would expect that when I "compile" or minify the code, all the instances of document.createElement are replaced with the c
function.
I would do the same for other methods: document.getElementById, etc. I am hoping that I can shorten my code by 10 to 20% with this technique.
Are there minifiers or compilers that can do this? And does it make sense in the first place?
I don't think it will gain you that much. The uncompressed js file might be quite a bit smaller, but compression should deal with with such a repetitive string. So I expect the gain on a compressed(http gzip compression) javascript file to be rather small.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With