我是第一次创建插件,并面临重大问题的缓存。
我将js文件注册为
wp_register_script("custom-js-backend", PLUGIN_URL . 'assets/js/custom.js', array(
'jquery',
'jquery-blockui'
));
wp_enqueue_script("custom-js-backend");但无法反映管理面板上的更改。
尝试过
function cache_cleanup()
{
remove_action('wp_head', 'wp_generator');
remove_action('wp_footer', 'wp_generator');
}
add_action('init', 'cache_cleanup'); 也在wp-config.php中定义。
define('WP_CACHE',false);但没有运气。
由于默认情况下,我的js文件附带了5.1.0版本,所以尝试使用https://wordpress.org/plugins/disable-version-caching/从其中删除该版本
现在正在删除版本,但仍然没有更新文件。
一种解决方案是在我的js文件中添加版本号,并在每次更改后更改版本,但这是不对的。
任何帮助如何禁用缓存管理面板,同时创建插件。
发布于 2020-09-11 10:45:10
您可以使用filemtime(PLUGIN_URL . 'assets/js/custom.js')作为版本号-它将生成版本号,即上次保存文件时的unix时间-
这意味着,每次您相同的文件,您会自动获得一个新的版本号高于上一个版本号,这样它仍然是可缓存的,但当有更改时将被清除。
所以看起来就像
wp_register_script("custom-js-backend", PLUGIN_URL . 'assets/js/custom.js', array(
'jquery',
'jquery-blockui'
), filemtime(PLUGIN_URL . 'assets/js/custom.js'), true);发布于 2020-09-28 13:34:19
在开发期间将其添加到.htaccess到disable browser caching中:
# Disable browser caching.
# Ensure mod_headers is installed.
# To install on Debian, run `a2enmod headers`, then restart the server.
FileETag None
Header unset ETag
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
Header set Pragma "no-cache"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"注意:您的浏览器仍然可以缓存来自CDN的外部内容,但是服务器上的任何内容都不会被缓存。
https://stackoverflow.com/questions/63845128
复制相似问题