Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Split polyfill #617

Closed
wants to merge 3 commits into from

2 participants

@shalecraig

I modified String.prototype.trim to a smaller version, which is attributed to MDN.

Before my revision we were at:

Minified: 24.916k
Minified and gzipped: 9.080k, compression factor 5.599

Now, we're at:

Minified: 24.897k
Minified and gzipped: 9.080k, compression factor 5.608

I'm not sure how to remove commit 4c557d1, but it's already been merged.

shalecraig added some commits
@shalecraig shalecraig Fixed a test bug 4c557d1
@shalecraig shalecraig Commit to reduce the size of Zepto.
Now using the official MDN String.prototype.trim polyfill, as
opposed to our own home-baked one.

The Uglifyjs compiler doesn't make this optimization, but Google's
Closure uses inferred types to make "safe" changes like this:

if (x === undefined) {
    x = foo();
}

to:

x = x || foo();

UglifyJS doesn't make these changes. We might want to consider
moving to Closure compiler, if our aim is to produce the smallest js
possible.
5faaad1
@shalecraig shalecraig Removed newline at end of the file, so I added it again.
Oops.
4b490a5
@madrobby madrobby closed this in 3771d17
@lopper lopper referenced this pull request from a commit in buddydvd/zepto
@madrobby Shorter RegExp for trim polyfill. Fixes #617 c4b45c5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 5, 2012
  1. @shalecraig

    Fixed a test bug

    shalecraig authored
Commits on Oct 17, 2012
  1. @shalecraig

    Commit to reduce the size of Zepto.

    shalecraig authored
    Now using the official MDN String.prototype.trim polyfill, as
    opposed to our own home-baked one.
    
    The Uglifyjs compiler doesn't make this optimization, but Google's
    Closure uses inferred types to make "safe" changes like this:
    
    if (x === undefined) {
        x = foo();
    }
    
    to:
    
    x = x || foo();
    
    UglifyJS doesn't make these changes. We might want to consider
    moving to Closure compiler, if our aim is to produce the smallest js
    possible.
  2. @shalecraig
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 4 deletions.
  1. +6 −3 src/polyfill.js
  2. +1 −1  test/zepto.html
View
9 src/polyfill.js
@@ -3,11 +3,14 @@
// Zepto.js may be freely distributed under the MIT license.
;(function(undefined){
- if (String.prototype.trim === undefined) // fix for iOS 3.2
- String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') }
+ // fix for iOS 3.2
+ // from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim
+ String.prototype.trim =
+ String.prototype.trim ||
+ function () { return this.replace(/^\s+|\s+$/g,'') }
// For iOS 3.x
- // from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
+ // Adapted from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
if (Array.prototype.reduce === undefined)
Array.prototype.reduce = function(fun){
if(this === void 0 || this === null) throw new TypeError()
View
2  test/zepto.html
@@ -287,7 +287,7 @@
if (typeof expected.get == 'function') expected = expected.get()
if (typeof actual.get == 'function') actual = actual.get()
- if (passed) for (var i=0; i<expected.length; i++) passed = expected[i] == actual[i]
+ if (passed) for (var i=0; i<expected.length; i++) passed &= expected[i] == actual[i];
this._assertExpression(passed, message || 'Failed assertion.',
'Expected %o, got %o.', expected, actual)
Something went wrong with that request. Please try again.