WordPress optimization: disable website static resource version query

» WordPress » WordPress optimization: disable website static resource version query

The optimization of WordPress is achieved by disabling the version query of WordPress static resources. Remove Query strings from Static Resources

preface

Our website often sees some problems in the following figure, explaining that the link will have a version number, such as:

 http://sitename.com/wp-content/plugins/js/some_js?ver=3.4.2

WordPress优化:禁用网站静态资源版本查询-极客公园

On this question, you can see this English explanation

Generally, JS code or CSS code is called. The later version number can help cache refresh quickly. If your JS or CSS code no longer needs frequent changes, you can consider not increasing the version number.

function code

Add the following code to the functions.php file

 /** Remove Query strings from Static Resources. */ 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 );

Recommended reading

http://www.digitalskydesign.com/how-to-remove-query-strings-from-static-resources-in-wordpress/
https://developers.google.com/speed/docs/insights/LeverageBrowserCaching#LeverageProxyCaching
http://diywpblog.com/wordpress-optimization-remove-query-strings-from-static-resources/

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

One Reply to "WordPress optimization: disable website static resource version query"