how to Remove query strings from static resources
-
I was messuring load time with pingdom.com/tools.
they reccoment Remove query strings from static resources.
How do I do that?
-
What they are recommending is that you look for queries where the result never changes. Replace those queries with the HTML that was generated from the queries.
thanks for replying but this souds like chinese to me:-)
Wouldn’t know where to look forThis recommendation may point to a file created by w3 total cache. In my case, pingdom is referring to a file which (I’m guessing) is on the disc cache, which w3c finds using a query for example:
.../w3tc/min/index.php?file=635bc/default.include.nnnnn.cxxAny way round this?
yes that may be due to W3TC: i’ve got a bunch of them.
here are some of them
/wp-content/plugins/clickdesk-live-support-chat-plugin/js/widget.js?9d8528
/wp-content/plugins/contact-form-7/jquery.form.js?9d8528
/wp-content/plugins/contact-form-7/scripts.js?9d8528
/wp-content/plugins/contact-form-7/styles.css?9d8528
/wp-content/plugins/count-per-day/counter.css?9d8528
/wp-content/plugins/dmsguestbook/dmsguestbook.css?9d8528
/wp-content/plugins/google-analytics-for-wordpress/custom_se_async.js?9d8528
/wp-content/plugins/jetpack/modules/wpgroho.js?9d8528
/wp-content/plugins/share-and-follow/images/blank.gif?9d8528
/wp-content/plugins/wp-photo-album-plus/images/tick.png?9d8528
/wp-content/plugins/wp-photo-album-plus/theme/wppa-style.css?9d8528
/wp-content/plugins/wp-photo-album-plus/wppa-slideshow.js?9d8528
/wp-content/plugins/wp-photo-album-plus/wppa-theme.js?9d8528
/wp-content/themes/atahualpa373/js/jquery.cross-slide.js?9d8528
/wp-content/uploads/2010/06/we-hebben-kittens11.gif?9d8528
/wp-includes/js/comment-reply.js?9d8528
/wp-includes/js/l10n.js?9d8528
/wp-includes/js/thickbox/thickbox.css?1
/wp-includes/js/thickbox/thickbox.js?9d8528
pingdom says: Remove the query string and encode the parameters into the URL for the following resources.
How do I do that?I just ran across this post sharepointjohn.com and it has two filters you can add to remove stylesheets and javascript.
If you Use “W3 Total Cache” – W3TC you may switch off “Prevent caching of objects after settings change” in Browser Cache.
This removes query strings from static resources.
best Regards
Robert
hi Justin tried the code at sharepointjohn.com but it brakes my site so that wont work for me.
Robertkn
Thanks for your suggestion will try that oneJustin Givens has given me the solution i was looking for. Thank you, now my site performance in PageSpeed is 90 😀
I add the following code to remove the query strings from CSS & JS and it worked on all but the following http://yourgreendrycleaner.com/wp-content/plugins/audio-player/assets/audio-player.js?ver=2.0.4.1 … any suggestions?
function _remove_script_version( $src ){
$parts = explode( ‘?’, $src );
return $parts[0];
}
add_filter( ‘script_loader_src’, ‘_remove_script_version’, 15, 1 );
add_filter( ‘style_loader_src’, ‘_remove_script_version’, 15, 1 );@leonel
placed your code in my .htaccess, breaks my site@leonelleonel, edit plugin file …audio-player.php
change 715 line
echo '<script type="text/javascript" src="' . $this->pluginURL . '/assets/audio-player.js?ver=' . $this->version . '"></script>';
to
echo '<script type="text/javascript" src="' . $this->pluginURL . '/assets/audio-player.js"></script>';@kletskater, this code is not for .htaccess, but for functions.php
@kletskater, I concur with adpawl, you should place the code in your theme’s function file (Appearance > Editor > Functions.php)and add it before the closing PHP tag
@adpawl, thanks! that worked …
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:
getting this problem please help me
RobertKn is right. W3 Total Cache could cause this problem. Take a look at this post:
The code worked wonders on my site, however it didn’t remove the query string from the theme’s .css and .js files as these are not version strings. any thoughts on how i can get rid of these?
The topic ‘how to Remove query strings from static resources’ is closed to new replies.