Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm getting nags on google speed test regarding the querystrings in my scripts. So, I'm trying to remove them by passing false as the argument for that parameter. However, it does not seem to have effect:

wp_register_script('myscript', get_bloginfo('template_directory').'/scripts.myversionnumber.js',false,false,true);
wp_enqueue_script('myscript');

PS: the "myversionnumber" part of the js filename is my means of controlling cache/versioning rather than the ?ver= approach which apparently trips up some proxy servers (according to Google pagespeed test):

Remove query strings from static resources Enabling public caching in the HTTP headers for static resources allows the browser to download resources from a nearby proxy server rather than from a remote origin server. Learn more

Suggestions for this page

Resources with a "?" in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:

share|improve this question
    
Interesting question, never knew that query strings would trip up page speed. While I don't have a solution, lemme comment on setting the parameter to "false": Afaik, you either enter a version number, or it defaults to the current wordpress version. –  Johannes Pille May 17 '12 at 16:15
    
I thought that the script would be cached, even with a version number - and that altering the version number would 'break' the cache, purposefully so that the new, rather than old, script would be loaded.... –  Stephen Harris May 17 '12 at 18:37
    
@Stephen, that's the idea exactly. However, apparently some proxy cache servers will not cache resource URLs with querystring params. That's why I'm opting to encode the params in the filename instead. Same effect, less baggage. –  Scott B May 18 '12 at 13:15
    
Hello Scott B. I am facing the same problem. After I run a test on gtmetrix I am getting errors for the query. Did the solution provided by @SickHippie work for you? Is it safe to use it? –  kat_indo Nov 3 '13 at 20:16
add comment

2 Answers

up vote 4 down vote accepted

I think you have to pass NULL as the 4th parameter.

wp_register_script(
    'myscript',
    get_bloginfo('template_directory').'/scripts.myversionnumber.js',
    false,
    NULL,
    true);
wp_enqueue_script('myscript');
share|improve this answer
add comment

You can pass null as the version value to wp_register_script or wp_enqueue_script and it should drop the query string.

<?php
wp_enqueue_script(
   'myscript',
   '/path/to/script.js',
   array(),
   null
);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.