Permalink
Browse files

Serialize: Reduce size

  • Loading branch information...
gibson042 committed Apr 5, 2016
1 parent 9fdbdd3 commit 91850ecbbe04ad8f5d89dc050aa1d9002047c435
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/serialize.js
View
@@ -55,14 +55,15 @@ function buildParams( prefix, obj, traditional, add ) {
jQuery.param = function( a, traditional ) {
var prefix,
s = [],
add = function( key, value ) {
add = function( key, valueOrFunction ) {
// If value is a function, invoke it and return its value
value = jQuery.isFunction( value ) ? value() : value;
if ( value == null ) {
value = "";
}
s[ s.length ] = encodeURIComponent( key ) + "=" + encodeURIComponent( value );
// If value is a function, invoke it and use its return value
var value = jQuery.isFunction( valueOrFunction ) ?
valueOrFunction() :
valueOrFunction;
s[ s.length ] = encodeURIComponent( key ) + "=" +
encodeURIComponent( value == null ? "" : value );

This comment has been minimized.

Show comment
Hide comment
@alecpl

alecpl Apr 5, 2016

(value == null ? "" : encodeURIComponent( value )); wouldn't be better?

@alecpl

alecpl Apr 5, 2016

(value == null ? "" : encodeURIComponent( value )); wouldn't be better?

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol Apr 5, 2016

Member

If you want to know, check it yourself. :) grunt prints the final gzipped size.

@mgol

mgol Apr 5, 2016

Member

If you want to know, check it yourself. :) grunt prints the final gzipped size.

This comment has been minimized.

Show comment
Hide comment
@rentalhost

rentalhost Jun 11, 2016

I guess that @alecpl just said that is better not call encodeURIComponent(""), because is possible avoid this function call if value is null. But it increase gzipped size in 4 bytes.

@rentalhost

rentalhost Jun 11, 2016

I guess that @alecpl just said that is better not call encodeURIComponent(""), because is possible avoid this function call if value is null. But it increase gzipped size in 4 bytes.

};
// Set traditional to true for jQuery <= 1.3.2 behavior.

1 comment on commit 91850ec

@kafeltz

This comment has been minimized.

Show comment
Hide comment
@kafeltz

kafeltz Apr 7, 2016

I kinda like the new solution

kafeltz commented on 91850ec Apr 7, 2016

I kinda like the new solution

Please sign in to comment.