Skip to main content

Bug Tracker

Side navigation

#1999 closed bug (fixed)

Opened December 03, 2007 10:18PM UTC

Closed December 04, 2007 07:41AM UTC

Ajax: replace cache value in URL when cache === false, type == get and key (_) already exists

Reported by: emartin24 Owned by:
Priority: major Milestone: 1.2.2
Component: ajax Version: 1.2.1
Keywords: cache, ajax Cc:
Blocked by: Blocking:

I ran into an issue today where the ajax cache prevention parameter (_=(new Date()).getTime()) is being continuously appended to a URL.

I'm using livequery for an ajax call and after a few clicks, I end up with URL's that look like:

My expectation would be that jQuery would look to see if this key already existed and if it did, replace the value with a new timestamp.

I've attached a patch. It could be optimized and perhaps changed to use a RegExp, but it works ;)



Attachments (1)
  • ajax_cache.patch (1.3 KB) - added by emartin24 December 03, 2007 10:18PM UTC.

    patch with possible solution

Change History (4)

Changed December 04, 2007 04:46AM UTC by davidserduke comment:1

resolution: → fixed
status: newclosed

Fixed in [4006].

Changed December 04, 2007 05:32AM UTC by emartin24 comment:2

resolution: fixed
status: closedreopened

Thanks - a much more elegant solution =)

There is one issue however, your replace is greedy and will match the rest of the query string. It just needs to be changed from:

var ret = url.replace(/(\\?|&)_=.*(&|$)/, "$1_=" + ts + "$2");


var ret = url.replace(/(\\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); // add ? in front of (&|$)



Changed December 04, 2007 05:38AM UTC by emartin24 comment:3

Sorry, I mean:

var ret = s.url.replace(/(\\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2");

That should be s.url.replace, not url.replace

Changed December 04, 2007 07:41AM UTC by davidserduke comment:4

resolution: → fixed
status: reopenedclosed

Thanks for the catch! I actually had that in my test case and apparently it got lost getting in to jQuery. The fix is in [4007].