Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome not caching JSON responses

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.

request

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.

response

However, the server logs show that there was a request made to the API.

logs

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.

like image 389
rectangletangle Avatar asked Jul 22 '14 01:07

rectangletangle


People also ask

Does browser cache JSON response?

Request Headers 2nd request: Thx for response. Yes you can cache JSON responses.

Does Chrome cache scripts?

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.


1 Answers

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

like image 149
zerkms Avatar answered Sep 24 '22 02:09

zerkms