Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#13759 closed feature (fixed)

Better undefined gzip compression

Reported by: m_gol Owned by: m_gol
Priority: low Milestone: None
Component: build Version: 2.0.0-beta3
Keywords: Cc:
Blocked by: Blocking:

Description (last modified by m_gol)

We can compress better if we tell uglifyjs to not mangle undefined, as suggested by dcherman.

----- ORIGINAL TEXT -----
According to ES5.1, undefined is immutable. All supported in 2.0 browsers besides Android <4.1 (including iOS 5.1 and VERY old Safari) adhere to that.

Removing undefined from the main IIFE parameters saves 62 bytes in the gzipped minified file.

I'm putting it here for a discussion. If we decided to go for that, we also have to decide what to do about 1.x

Change History (14)

comment:1 Changed 9 years ago by Rick Waldron


comment:2 Changed 9 years ago by timmywil

Component: unfiledbuild
Priority: undecidedlow
Status: newopen

Even Android?

comment:3 Changed 9 years ago by m_gol

@timmywil, please read my report again, I covered Android.

comment:4 Changed 9 years ago by timmywil

Oh, sorry. I don't even know which Android browsers we want to support.

comment:5 Changed 9 years ago by m_gol

I guess >= 2.3 currently, unfortunately. :( Anyway, I doubt anyone writes sites only for Android <4.1 so relying on the ability to redefine undefined wouldn't work.

comment:6 Changed 9 years ago by m_gol

IE seems to have mutable undefined, after all. I used kangax tables for desktop browsers:
but they seem to be wrong about IE9.

Anyway, the spec must be more complicated than what I anticipaded. The following code provides the same results in Chrome, Firefox, Opera & IE10 (IE9 results in [0, 1, ..., 7]):

var results = [];

var undefined = 0;
results.push((function () {
	return undefined;
})()); // => undefined

var undefined = 1;
results.push((function () {
	'use strict';
	return undefined;
})()); // => undefined

results.push((function ( undefined ) {
	return undefined;
})( 2 )); // => 2

results.push((function ( undefined ) {
	'use strict';
	return undefined;
})( 3 )); // => 3

results.push((function () {
	var undefined = 4;
	return undefined;
})()); // => 4

results.push((function () {
	'use strict';
	var undefined = 5;
	return undefined;
})()); // => 5

results.push((function () {
	undefined = 6;
	return undefined;
})()); // => 6

results.push((function () {
	'use strict';
	try {
		undefined = 7;
		return undefined;
	} catch (e) {
		return e;
})()); // => TypeError

results; // [undefined, undefined, 2, 3, 4, 5, undefined, TypeError]
Version 0, edited 9 years ago by m_gol (next)

comment:7 Changed 9 years ago by m_gol

On jsFiddle every browser behaves like IE9, though...


comment:8 Changed 9 years ago by dmethvin

On IRC, dcherman suggested just telling uglify to not compress undefined, which he says saves 40-something bytes. Not quite as much saved, but no downside.

comment:9 Changed 9 years ago by m_gol

Yeah... I didn't suspect ES5's meaning of undefined is that you can't do undefined = 'a' but you can do var undefined = 'a'. Sooo helpful...

comment:10 Changed 9 years ago by m_gol

Description: modified (diff)
Summary: Remove undefined from the main IIFE parametersBetter undefined gzip compression

comment:11 Changed 9 years ago by m_gol

Owner: set to m_gol
Status: openassigned

comment:12 Changed 9 years ago by m_gol

Description: modified (diff)

comment:13 Changed 9 years ago by Michał Gołębiowski

Resolution: fixed
Status: assignedclosed

Tell uglifyjs to not mangle undefined; saves 44 bytes. Fixes #13759. Close gh-1239.

Changeset: 8576e24bfe3fce886bcb63ebc24ee16b3fa1a6a1

comment:14 Changed 9 years ago by m_gol

BTW, orkel was right, this change actually increases the gzipped 1.x-master size so it makes sense only on master.

Note: See TracTickets for help on using tickets.