Bug Tracker

Ticket #3004 (new enhancement)

Opened 3 months ago

Last modified 2 months ago

cache option for getScript

Reported by: eitanpo Assigned to: anonymous
Type: enhancement Priority: major
Milestone: 1.3 Component: ajax
Version: 1.2.6 Keywords: getScript cache
Cc: Needs: Review

Description

now, in order to enable cache for loading scripts from another domain you have to change global ajax setting with ajaxSetup, and then to restore the original ajax settings.

cache option or options attribute for getScript can make life easier. example for this is using hosted javascript libraries like YUI.

Attachments

Change History

Changed 3 months ago by ygirouard

Correct me if I'm wrong, but I thought .get, .post, .getJSON, .getScript, and .load were only shortcuts and simplified versions that wrap the more complex functionalities of .ajax().

If you want to have a cache option, then you should probably use $.ajax(options), and set the cache setting accordingly. It's not that hard to master and it does a lot more than the simplified versions...

i.e.:

var data = {param1:"value1",param2:"value2"};
var options = {
 data: data,
 url: "ajax.php",
 dataType: "script",
 cache: false,
 type: "GET"
 success: function(r){
  // DO SOMETHING ELSE HERE IF NEEDED
 }
}
$.ajax(options);

This will have the same effect as if you were using $.getScript() but you have some extra control.

Changed 2 months ago by eitanpo

You are right, but this will make code less readable. Ease of use is an important reason too. My guess is that why getScript function is present in jQuery.

Why not code like this:

$.getScript("http://domain.com/script.js", {cache: true});

or

$.getScript("http://domain.com/script.js", true);

I think that .getScript is the only exception out of other .ajax wrappers to have cache control.

Note: See TracTickets for help on using tickets.