Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 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 10 years ago by Rick Waldron

+1

comment:2 Changed 10 years ago by Timmy Willison

Component: unfiledbuild
Priority: undecidedlow
Status: newopen

Even Android?

comment:3 Changed 10 years ago by m_gol

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

comment:4 Changed 10 years ago by Timmy Willison

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

comment:5 Changed 10 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 10 years ago by m_gol

IE seems to have mutable undefined, after all. I used kangax tables for desktop browsers:
http://kangax.github.io/es5-compat-table/
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]):

(function ( undefined ) {
	console.log('0: ' + undefined);
})( 0 ); // => 0

(function ( undefined ) {
	'use strict';
	console.log('1: ' + undefined);
})( 1 ); // => 1

(function () {
	undefined = 2;
	console.log('2: ' + undefined);
})(); // => 2

(function () {
	'use strict';
	try {
		undefined = 3;
		console.log('3: ' + undefined);
	} catch (e) {
		console.log('3: ' + e);
	}
})(); // => TypeError

(function () {
	var undefined = 4;
	console.log('4: ' + undefined);
})(); // => 4

(function () {
	'use strict';
	var undefined = 5;
	console.log('5: ' + undefined);
})(); // => 5

var undefined = 6;
(function () {
	console.log('6: ' + undefined);
})(); // => undefined

var undefined = 7;
(function () {
	'use strict';
	console.log('7: ' + undefined);
})(); // => undefined
Version 1, edited 10 years ago by m_gol (previous) (next) (diff)

comment:7 Changed 10 years ago by m_gol

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

http://jsfiddle.net/m_gol/3KrZW/2/

comment:8 Changed 10 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 10 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 10 years ago by m_gol

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

comment:11 Changed 10 years ago by m_gol

Owner: set to m_gol
Status: openassigned

comment:12 Changed 10 years ago by m_gol

Description: modified (diff)

comment:13 Changed 10 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 10 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.