How can I guarantee that the ajax response will be cached?

I want to make an ajax call, but I want to make sure it will be cached. I am using jquery.

Is there any way to make sure that the request remains in the cache for most popular browsers?

+3
source share
4 answers

With jQuery, you probably want to explicitly add an If-Modified-Since header with a parameter ifModifiedthat is false by default:

$.ajax({
     ...
     ifModified: true,
     ...
});

There is also an option cachethat you will need to force true if your data type is jsonpor script. This is true by default for other data types.

For a description of these options, see jQuery.ajax()docs .

+8

GET ( ..), POST .

.

+2

http, Expires Cache-control.

. , , :

  • ( )
  • (Cache-control: public header)

, " resposne", ( ). ,

  • ( ), ,
  • E-Tag , -, , . , ... etags .

. , cookie , cookie, , cookie, .

+1

, AJAX , . jQuery Cache (?).

+1

Source: https://habr.com/ru/post/1708810/


All Articles