homm2011-09-13 09:33:52
homm, 2011-09-13 09:33:52

Ajax cache in jquery - where is the logic here?

Among the numerous parameters of the jQuery.ajax method, there is a cache parameter with the following description:

> cache
> Default: true, false for dataType 'script' and 'jsonp'

Personally, I don't understand why this is done, maybe this behavior is logical for some tasks which I don't encounter.

My reasoning is that the "script" type is used to load scripts asynchronously with the getScript function. They rarely change and should be cached as hard as possible. The remaining types of requests are for obtaining up-to-date data from the application. They don't need to be cached.

Why is jQuery doing the opposite?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
serega011, 2011-09-13

Apparently people think that it often happens that a request with the same parameters at the same address returns the same thing, which means you can cache. If this behavior does not suit you, disable caching.

andruxin, 2011-09-13

Well, if you receive a script with an ajax request, then it is assumed that there will be some kind of dynamics in it (depending on the environment). Same with json.
I don't see any clue here at all. If you don't need it, turn it off, if you need it, turn it on. Another question is if caching was enabled all the time and every time you had to come up with crutches to turn it off.

akzhan, 2011-09-13

This is a rhetorical question. Just keep in mind.

Anatoly, 2011-09-13

because _not_ scripts and jsonp are static, the rest is dynamic. The same html pages are cached for a long time, but php (even with the same get parameters) is not, because that's why they are "dynamic".

Vladimir Chernyshev, 2011-09-14

Apparently it means that scripts and json are dynamically generated by the server (this is especially true for json with, for example, the REST API), otherwise it is easier to get them through html. And html/xml/png/jpg/… are assumed to be static - dynamic loading of static content in response to user actions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question