Bug Tracker

Modify

Ticket #8487 (closed bug: wontfix)

Opened 2 years ago

Last modified 2 years ago

Cache option for .getScript

Reported by: rudeboiidevil2k7@… Owned by:
Priority: undecided Milestone: 1.next
Component: ajax Version: 1.5.1
Keywords: Cc: jaubourg
Blocking: Blocked by:

Description

From now on, the .getScript function should allow the use of caching, since when using the .getScript uses a simple .get() of a script without caching, so I demand that there should be an option for .getScript to allow caching when being used.

getScript: function( url, callback ) {
	return jQuery.get( url, undefined, callback, "script" );
},

Should be changed to:

getScript: function( url, cache, callback ) {
	$.ajax({
		type: "GET",
		url: url,
		success: callback,
		dataType: "script",
		cache: cache
	})
},

Or anything that the jQuery team should take action onto changing .getScript to be more flexible with options.

Let us see this change to be added into 1.5.2 or the next update!

Change History

comment:1 Changed 2 years ago by jaubourg

  • Cc jaubourg added
  • Resolution set to wontfix
  • Status changed from new to closed
  • Component changed from unfiled to ajax

Just use ajax directly, not a helper, if you have this kind of specific needs. It's quite simple with the new signature and deferreds:

var getCachedScript = {
    type: "GET",
    dataType: "script",
    cache: true
};

jQuery.ajax( url, getCachedScript ).success( callback );

Alternativaly, you can use a prefilter if you wanna ensure all script requests are cached:

jQuery.ajaxPrefilter( "script", function( options ) {
    options.cache = true;
} );

You could also code your own helper:

jQuery.getCachedScript = function( url, callback ) {
    jQuery.ajax({
        type: "GET",
        url: url,
        success: callback,
        dataType: "script",
        cache: true
    });
};

As you can see, you have lots of options and alternatives. Changing the helpers signature is to avoid as much as possible, especially when simple alternatives exist. Let's try to avoid the bloat as much as possible.

comment:2 Changed 2 years ago by jaubourg

#8633 is a duplicate of this ticket.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.