Skip to content

Commit

Permalink
Serialize: Reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
gibson042 committed Apr 5, 2016
1 parent 9fdbdd3 commit 91850ec
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Copy link
@alecpl

alecpl Apr 5, 2016

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

This comment has been minimized.

Copy link
@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.

Copy link
@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.
Expand Down

1 comment on commit 91850ec

@kafeltz
Copy link

@kafeltz kafeltz commented on 91850ec Apr 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kinda like the new solution

Please sign in to comment.