Permalink
Browse files

Serialize: Reduce size

  • Loading branch information...
1 parent 9fdbdd3 commit 91850ecbbe04ad8f5d89dc050aa1d9002047c435 @gibson042 gibson042 committed Apr 5, 2016
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 );
@alecpl
alecpl Apr 5, 2016

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

@mgol
mgol Apr 5, 2016 Member

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

@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
kafeltz commented on 91850ec Apr 7, 2016

I kinda like the new solution

Please sign in to comment.