I have a Django project with a view that has a lot of python code to calculate data for specific table in its template (2-4 seconds).
To improve user experience I decided to load template immediately with empty table and get necessary data via jQuery $.getJSON request.
$(document).ready(function() {
$(function() {
$.getJSON(devices_list_JSON, function(data){
// fill table data
...
}
}
}
I've done so and it works fine except of one issue.
When I go to some page and back to my view using browser Back button, browser make JSON request again.
And I want to use cached version as it was in a view that calculated all data in its python code.
How can I do so?
(I use Google Chrome 68.0.3440.106 browser)
ajaxcall, you can setcache: true, the request will however still be sent, but you get a cached answer.$.ajaxSetup({ cache: true});should do the work. You can test if it works with measuring the response time. First measure the time if you just reload the page, then measure the time if you reload it withctrl + F5, which will reset your cache