WordPress, Cloudflare, Caching & Version Numbers

While I love WordPress one thing that really bugs me is its insistence on adding the version number to the end of resources, so you end up with links links this:

http://www.spokenlikeageek.com/wp-content/themes/required/style.css?ver=4.4

The version number is added to enable browser caching of files thereby speeding up page loads. The issue with this is if you make a change to the resource it is difficult to get the changes showing without clearing your cache. Additionally, as I am using CloudFlare this step by WordPress is superfluous.

All is not lost however, you can remove these version number by adding the following snippet of code to your themes functions.php file, ideally in the child theme.


function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );

It is then a simple matter of either refreshing your browser to see the change or to remove the copy from CloudFlare’s cache. Go to the Caching section and click the Purge Individual Files button:

Caching__spokenlikeageek_com___CloudFlare_-_Web_Performance___Security

Then add the files you want purging from the cache in the box:

Caching__spokenlikeageek_com___CloudFlare_-_Web_Performance___Security

Give it a minute or so, refresh you page and you will no longer have the version numbers appended to the end of resources and you will quickly be able to see the results of any change syou make.

Source: https://wordpress.org/support/topic/get-rid-of-ver-on-the-end-of-cssjs-files

Leave a Reply

Your email address will not be published. Required fields are marked *