How to control cache-control in ajax request

前端 未结 1 1379
逝去的感伤
逝去的感伤 2021-01-12 03:12

This might be a stupid question, but I searched a lot without any result. I know how to setup cache-control in server responses, but how can I change the cache control value

1条回答
  •  日久生厌
    2021-01-12 03:53

    You can use headers property, like this:

    $.ajax({
    ...
    headers: {
         'Cache-Control': 'max-age=1000' 
    }
    ...
    });
    

    Keep in mind that cache property has nothing in common with Cache-Control header, it's just a cache buster (appending ?_={timestamp} to GET parameters) and will only work correctly with GET and HEAD requests.

    Anyway, something useful: How to set HTTP headers (for cache-control)?

    0 讨论(0)
提交回复
热议问题