Strange underscore param in remote links

这一生的挚爱 提交于 2020-01-01 09:46:47

问题


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.


回答1:


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)




回答2:


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

jQuery.ajaxSetup({ cache: true });



回答3:


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);.



来源:https://stackoverflow.com/questions/5355667/strange-underscore-param-in-remote-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!