生命不息,奋斗不止/创造价值-传递价值-获得价值
所谓迷茫,就是才华配不上梦想 每一个让你难堪的现在,都有一个不够努力的曾经

WordPress优化:禁用网站静态资源版本查询

我们网站经常会看到下图的一些问题,解释链接后面会有版本号,比如:

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

WordPress 优化:禁用网站静态资源版本查询
关于这个问题,可以看看这段英文解释

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 代码不再需要频繁改变,那么可以考虑不再增加版本号。

函数代码

将下面这段代码加入 functions.php 文件即可

  1. /** Remove Query strings from Static Resources. */
  2. function _remove_script_version( $src ){
  3. $parts = explode(‘?’, $src );
  4. return $parts[0];
  5. }
  6. add_filter(‘script_loader_src’,‘_remove_script_version’,15,1);
  7. add_filter(‘style_loader_src’,‘_remove_script_version’,15,1);
赞(0)
未经允许不得转载:jack361博客 » WordPress优化:禁用网站静态资源版本查询

如果你爱我或恨我,请↓

联系我