• Blogs (9)
    • 📱 236 - 992 - 3846

      đź“§ jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • ajax: Automatically refresh webpage

    Blogs20112011-11-11


    ajax: Automatically refresh webpage

    Every web developer/designer meets such issue: the webpage sometimes doesn’t refresh when clicking browser’s refresh button.

    Here is the issue of browser cache. The browser cache management sometimes is out of our expectation, very weird, especially:

    • with multi-css and js files, as well as ajax.
    • with anchor

    if you are in the period of debuging and testing, definately you expect it refresh everytime your modification. Here I list a simple solution like this:

    $(document).ready(function() {
     var debug = true;
     $.rt = function() {
      return new Date().getTime();
     };
     ...
     if(debug}
      window.location.href='t.php?rt='+$.rt()+'&'+param+'='params;
     else
      window.location.href='index.php';

    When in debug mode (debug=true), everytime when you click, the browser cache will be refreshed by force, because the rt param changes: the current time in millisecond is always different.