通过禁用WordPress静态资源的版本查询来实现WordPress的优化,Remove Query strings from Static Resources
我们网站经常会看到下图的一些问题,解释链接后面会有版本号,比如:
- http://sitename.com/wp-content/plugins/js/some_js?ver=3.4.2
关于这个问题,可以看看这段英文解释
Most proxies, most notably Squid up through version 3.0, do not cache resources with a "?" in their URL even if a Cache-control: public header is present in the response. To enable proxy caching for these resources, remove query strings from references to static resources, and instead encode the parameters into the file names themselves.
一般常常是调用JS代码或CSS代码,后面的版本号可以帮助缓存快速刷新,如果你的JS或CSS代码不再需要频繁改变,那么可以考虑不再增加版本号。
一般常常是调用JS代码或CSS代码,后面的版本号可以帮助缓存快速刷新,如果你的JS或CSS代码不再需要频繁改变,那么可以考虑不再增加版本号。
函数代码
将下面这段代码加入functions.php文件即可
/** 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 );
如若转载,请注明出处:https://www.ozabc.com/jianzhan/166937.html