Case1: There are two snippets of code that are very similar and very gzip-able, one at the start of the document and the other is beyond 32kb at the end of the document. Does the minifier bring the two snippets together so that gzip will reach the second snippet?Case 2: A snippet of code is used multiple times. Gzip repeating it would take a byte. But if that snippet is put in a function, it would require 1 byte for function, at least 1 byte for the function name, 1 byte for () {, and one byte for }. Does the minifier turn functions back into repeated snippets of code for gzip?I'm sure there are more cases I haven't thought of, but these two have been on my mind for some time and I'd like to either put them to rest or start implementing them in my own code.
Do Javascript minifiers optimize for gzip?
javascript;optimization;minify
These are both highly unlikely, and I would actively avoid any optimiser which did make these transformations because I would suspect that it might have subtle bugs.Case1: There are two snippets of code that are very similar and very gzip-able, one at the start of the document and the other is beyond 32kb at the end of the document. Does the minifier bring the two snippets together so that gzip will reach the second snippet?Moving the two snippets together means reordering code. That might be perfectly safe, but determining whether it is safe or not is a hard problem (I'm sure that with a bit of effort there's an example which proves it undecidable).Case 2: A snippet of code is used multiple times. Gzip repeating it would take a byte. But if that snippet is put in a function, it would require 1 byte for function, at least 1 byte for the function name, 1 byte for () {, and one byte for }. Does the minifier turn functions back into repeated snippets of code for gzip?This would definitely be unsafe. The minifier has no way of knowing whether other JavaScript in a separate script accesses that function.