6

I use Rails3, JQuery and will_paginate gem to make remote pagination links. Known solution for this is:

$('.pagination a').live('click',function (){
  $.getScript(this.href);
  return false;
});

With this code I get links like: http://localhost:3000/products?_=1300468875819&page=1 or http://localhost:3000/products?_=1300468887024&page=2. So the little question is: what is this strange param _=1300468887024 (looks like Unix-time). What is its purpose? As I know this can cause some problems with search crawlers.

UPD: The solution is described here.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
sunki
  • 672
  • 11
  • 20

3 Answers3

8

it's a cache buster. It's also used in development mode, so to avoid getting an old request from the browser cache.

(unfortunately, all the explanations I found are realated to advertisement :S)

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • Should it appear in production (I also see it there)? How can and should I remove it? – sunki Mar 18 '11 at 17:40
  • I searched for a while, but I couldn't find a way to remove the timestamp :S. Maybe it's worth going into the source code of will_paginate and check where the timestamp is added to the link. I've read that some people cache the whole rendered area, which means that they return the same "links" to the user and because of that the urls can be cached. – Augusto Mar 18 '11 at 21:43
  • I have very similar project (same Rails, gems, rendering methods) without this stuff. The problem is that I cant see the difference. – sunki Mar 18 '11 at 22:09
1

This is a simple solution if you don't mind removing it for all requests:

jQuery.ajaxSetup({ cache: true });
DanS
  • 17,550
  • 9
  • 53
  • 47
0

Another solution would be to extend jQuery's getScript function as per the documentation:

jQuery.cachedScript = function(url, options) {
  options = $.extend(options || {}, {
    dataType: "script",
    cache: true,
    url: url
  });
  return jQuery.ajax(options);
};

This way, only the ajax calls using this new method will use the cache. On the other hand, if you used the ajaxSetup method, all your ajax calls would cache by default since ajaxSetup sets the cache property globally.

Now you can use $.cachedScript(location.href); instead of $.getScript(this.href);.

Ashitaka
  • 19,028
  • 6
  • 54
  • 69