jQuery: The Write Less, Do More JavaScript Library

Ticket #1999: ajax_cache.patch

File ajax_cache.patch, 1.3 kB (added by emartin24, 5 months ago)

patch with possible solution

  • ajax.js

     
    197197        if ( s.dataType == "script" && s.cache == null ) 
    198198            s.cache = false; 
    199199 
    200         if ( s.cache === false && s.type.toLowerCase() == "get" ) 
    201             s.url += (s.url.match(/\?/) ? "&" : "?") + "_=" + (new Date()).getTime(); 
     200        if ( s.cache === false && s.type.toLowerCase() == "get" ) { 
     201            var now = (new Date()).getTime(); 
     202            if (s.url.match(/\?/)) { 
     203                // Query string exists, check for cache key 
     204                if (s.url.match(/_=/)) { 
     205                    // Cache key exists, replace the value 
     206                    var parts = s.url.split("?"); 
     207                    var params = parts[1].split("&"); 
     208                    var newParams = []; 
     209                     
     210                    s.url = parts[0] + "?"; // Building the new url 
     211                    $(params).each(function (i) { 
     212                        if (this.match(/_=/)) { 
     213                           newParams[i] = "_=" + now; // Insert new value 
     214                        } else { 
     215                            newParams[i] = this; // Reuse existing value 
     216                        } 
     217                    }); 
     218                    s.url += newParams.join("&"); 
     219                } else { 
     220                    // cache key does not exist, add it 
     221                    s.url += "&_=" + now; 
     222                } 
     223            } else { 
     224                // query string does not exist, add cache key 
     225                s.url += "?_=" + now; 
     226            } 
     227        } 
    202228 
    203229        // If data is available, append data to url for get requests 
    204230        if ( s.data && s.type.toLowerCase() == "get" ) {