Response Caching
Cache AJAX responses on DOM elements to avoid redundant network requests when the same data is needed again.
Cache AJAX responses on DOM elements to avoid redundant network requests when the same data is needed again.
$(".tab").on("click", function() {
const type = $(this).data("type");
const cached = $(this).data("response");
if (cached) {
render(cached);
return;
}
$.getJSON("/api/items/" + type, function(data) {
$(this).data("response", data); // cache it
render(data);
}.bind(this));
});
Simple element-level caching works well for tab panels and accordion sections.