[wp-trac] [WordPress Trac] #24834: wp_enqueue_script passing null for $ver produces unexpected results
WordPress Trac
noreply at wordpress.org
Mon Aug 5 19:47:22 UTC 2013
#24834: wp_enqueue_script passing null for $ver produces unexpected results
--------------------------+-----------------------
Reporter: bobbingwide | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone:
Component: General | Version: 3.5.2
Severity: normal | Resolution:
Keywords: close |
--------------------------+-----------------------
Comment (by azaozz):
Replying to [comment:7 bobbingwide]:
> ...
> I could be invoking the JavaScript multiple times with different
parameters.
You're actually not invoking the JavaScript, you're loading it again and
again. Passing multiple arguments to a script can be done in a more
effective way from another script or number of scripts.
> So, in order to make it unique, the handle name has to contain the query
string.
> ...
> In my experience when the value for the $handle parameter contains a
query string ( such as when it matches the $src parameter, as in my
example) then the API doesn't work as expected... the value of null for
$ver is ignored.
The `handle` is the internal name of the script. It supports URL query
type syntax as a not recommended back-compat only. Anything passed after
the `?` in a script handle is treated (and outputted) as cache busting URL
query.
Btw, perhaps it's time to remove that back-compat bit from script handles.
It was a back-compat even 5 years ago. Think it's a left over from before
WP_Scripts supported explicit cache-busting arg.
Trying to guess what you want to do: load the same script multiple times
with different query strings (quite ineffective as the script will be
fully loaded each time). The needed query string can be in `$src` and a
`static` in your shortcode handling function can be used to make the
handle unique:
{{{
function _my_shortcode_handler() {
static $number = 1;
wp_enqueue_script( 'my-script-' . $number, $src, array("jquery"), ... );
$number++;
}
}}}
Suggesting closing as invalid.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/24834#comment:15>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list