Prevent browser caching of AJAX call result

后端 未结 21 1640
醉酒成梦
醉酒成梦 2020-11-22 04:47

It looks like if I load dynamic content using $.get(), the result is cached in browser.

Adding some random string in QueryString seems to solve this iss

21条回答
  •  离开以前
    2020-11-22 05:16

    All the answers here leave a footprint on the requested URL which will show up in the access logs of server.

    I needed a header based solution with no side effect and I found it can be achieved by setting up the headers mentioned in How to control web page caching, across all browsers?.

    The result, working for Chrome at least, would be:

    $.ajax({
       url: url, 
       headers: {
         'Cache-Control': 'no-cache, no-store, must-revalidate', 
         'Pragma': 'no-cache', 
         'Expires': '0'
       }
    });

提交回复
热议问题