Skip to main content

Bug Tracker

Side navigation

#3004 closed enhancement (wontfix)

Opened June 08, 2008 08:56AM UTC

Closed November 05, 2010 02:20AM UTC

Last modified March 14, 2012 10:08PM UTC

cache option for getScript

Reported by: eitanpo Owned by:
Priority: low Milestone: 1.5
Component: ajax Version: 1.2.6
Keywords: getScript cache Cc:
Blocked by: Blocking:
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 (1)
  • getpostoptions.patch (1.8 KB) - added by Rob Loach March 16, 2009 10:45PM UTC.

    jQuery.get/post options

Change History (6)

Changed June 10, 2008 07:50PM UTC by ygirouard comment:1

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 June 26, 2008 10:44AM UTC by eitanpo comment:2

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.

Changed March 16, 2009 10:47PM UTC by Rob Loach comment:3

The attached patch adds an options parameter to jQuery.get() and jQuery.post(), which is merged in with the defaults. This allows us to add an options parameter to the getScript() function, so we could essentially pass in {cache:true}, and it would merge it into the jQuery.ajax() call.

http://dev.jquery.com/attachment/ticket/3004/getpostoptions.patch

Changed October 21, 2010 07:11PM UTC by addyosmani comment:4

keywords: getScript cachegetScript cache needsreview
milestone: 1.31.5

This looks like it's going to be a wontfix. Marking for further review.

Changed October 22, 2010 06:26PM UTC by rwaldron comment:5

priority: majorlow

Updating to low priority

Changed November 05, 2010 02:20AM UTC by dmethvin comment:6

keywords: getScript cache needsreviewgetScript cache
resolution: → wontfix
status: newclosed

This is trivially easy to do by appending a random number to the url, or use $.ajax. $.getScript is meant to be simple and these changes would just complicate it.