jQuery.data() creates redundant objects upon data access
jQuery.data() creates an entry in the cache for a given element even
if the data is only accessed, not stored. As a result, cache gets
polluted with empty redundant objects. A small patch would fix the
problem:
Index: data.js
===================================================================
--- data.js (revision 6421)
+++ data.js (working copy)
@@ -14,18 +14,19 @@
if ( !id )
id = elem[ expando ] = ++uuid;
- // Only generate the data cache if we're
- // trying to access or manipulate it
- if ( name && !jQuery.cache[ id ] )
- jQuery.cache[ id ] = {};
+ // Prevent overriding the named cache with undefined values
+ if ( data !== undefined ) {
+ // Only generate the data cache if we're
+ // trying to manipulate it
+ if ( !jQuery.cache[ id ] )
+ jQuery.cache[ id ] = {};
- // Prevent overriding the named cache with undefined values
- if ( data !== undefined )
jQuery.cache[ id ][ name ] = data;
+ }
// Return the named cache data, or the ID for the element
return name ?
- jQuery.cache[ id ][ name ] :
+ jQuery.cache[ id ] && jQuery.cache[ id ][ name ] :
id;
},