admin管理员组文章数量:1287839
I have a WordPress website with medium-level traffic, ~10,000 unique visitors a day. Arround 30% of my daily visitors are recurrent. I constantly make some UI improvements: colors, font-size, javascript UX elements etc. Therefore on the same day, I can change .js and .css maybe 2 or 3 times. The problem is: the recurring visitors are viewing cached versions of the css/javascript files).
I've found this real useful script:
function my_load_scripts($hook) {
// create my own version codes
$my_js_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'js/custom.js' ));
$my_css_ver = date("ymd-Gis", filemtime( plugin_dir_path( __FILE__ ) . 'style.css' ));
//
wp_enqueue_script( 'custom_js', plugins_url( 'js/custom.js', __FILE__ ), array(), $my_js_ver );
wp_register_style( 'my_css', plugins_url( 'style.css', __FILE__ ), false, $my_css_ver );
wp_enqueue_style ( 'my_css' );
}
add_action('wp_enqueue_scripts', 'my_load_scripts');
This will make a versioning name based on the day the file its created, but I'm afraid to put it in public, because it will run everytime a user visit the website. And I'm afraid that the server can run out of resources.
Do you have another method?
本文标签: functionsAdvanced method to control cache of enqueued stylescript
版权声明:本文标题:functions - Advanced method to control cache of enqueued stylescript 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741256223a2366723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论