Bug Tracker

Modify

Ticket #13759 (closed feature: fixed)

Opened 12 months ago

Last modified 12 months ago

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:
Blocking: Blocked by:

Description (last modified by m_gol) (diff)

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

comment:1 Changed 12 months ago by rwaldron

+1

comment:2 Changed 12 months ago by timmywil

  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to build

Even Android?

comment:3 Changed 12 months ago by m_gol

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

comment:4 Changed 12 months ago by timmywil

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

comment:5 Changed 12 months 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 12 months 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
Last edited 12 months ago by m_gol (previous) (diff)

comment:7 Changed 12 months ago by m_gol

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

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

comment:8 Changed 12 months 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 12 months 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 12 months ago by m_gol

  • Description modified (diff)
  • Summary changed from Remove undefined from the main IIFE parameters to Better undefined gzip compression

comment:11 Changed 12 months ago by m_gol

  • Owner set to m_gol
  • Status changed from open to assigned

comment:12 Changed 12 months ago by m_gol

  • Description modified (diff)

comment:13 Changed 12 months ago by Michał Gołębiowski

  • Status changed from assigned to closed
  • Resolution set to fixed

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

Changeset: 8576e24bfe3fce886bcb63ebc24ee16b3fa1a6a1

comment:14 Changed 12 months 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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.