I'm writing an AJAX based auto-complete and am trying to keep my server from being inundated with requests by using client side caching. The setup is as follows, Django serving JSON responses on the back-end, with the client using jQuery's AJAX routines to GET
the appropriate data.
Looking at the response headers in Chrome, everything looks alright. The Cache-Control
header is present, so I'm pretty sure that the problem is outside of Django's scope.
However, the server logs show that there was a request made to the API.
Code:
This is the code I'm using to query the API.
function get(url, callback) {
jQuery.ajax({
type: 'GET',
contentType: 'application/json',
dataType: 'json',
cache: true,
url: url,
success: callback
});
}
Misc:
The little disable cache check-box isn't ticked, so Chrome should be caching responses.
Edit:
This is all set up in my development environment. So the server is serving from 127.0.0.1:8000
.
Request Headers 2nd request: Thx for response. Yes you can cache JSON responses.
Like other web browsers, Google Chrome features a cache that stores files such as images, scripts and video content from websites that you visit over time.
Chrome sends Cache-Control:max-age=0
in case if you open a page using address bar or F5.
That's it - if you want to see it working go to that page by a link click.
Related but obsolete answer: https://stackoverflow.com/a/385491/251311
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With