[英]Wordpress - reference JS-file without '?ver=4.6'
in my WP-Plugin I do enqueue my JS file 在我的WP插件中,我确实将JS文件放入队列
wp_enqueue_script('myjs', $pluginpath . 'build/js/app.min.js', array('jquery'));
so WP gererates the site-header: 因此WP产生了网站标题:
<script type='text/javascript' src='http://example.com/wp-content/plugins/myplugin/build/js/app.min.js?ver=4.6'></script>
this ?ver=4.6
causes, that when I make changes to the app.min.js, those aren't loaded.. instead a cached version of the `app.min.js' seems to be loaded 这个?ver=4.6
原因是,当我对app.min.js进行更改时,那些未加载..而是加载了“ app.min.js”的缓存版本
how can I avoid that? 我该如何避免呢?
Refer to the official documentation . 请参阅官方文档 。 The default value of $ver
is false, which sets the query string to the WP version you are using. $ver
的默认值为false,它将查询字符串设置为您正在使用的WP版本。 Use null
to turn it off: 使用null
将其关闭:
// Do not inject query string
wp_enqueue_script('myjs', $pluginpath . 'build/js/app.min.js', array('jquery'), null);
…or specify a version explicitly, say, '1.2.3': …或明确指定版本,例如'1.2.3':
// Use custom query string
wp_enqueue_script('myjs', $pluginpath . 'build/js/app.min.js', array('jquery'), '1.2.3');
wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )
$ver
: $ver
:
(string|bool|null) (Optional) String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. (string | bool | null)(可选)指定脚本版本号(如果有的话)的字符串,该脚本版本号作为查询字符串添加到URL中以用于缓存清除。 If version is set to false, a version number is automatically added equal to current installed WordPress version. 如果version设置为false,则会自动添加一个与当前安装的WordPress版本相同的版本号。 If set to null, no version is added. 如果设置为null,则不添加任何版本。
Default value: false So you should use this: 默认值:false因此,您应该使用以下命令:
wp_enqueue_script('myjs', $pluginpath . 'build/js/app.min.js', array('jquery'), null);
Looking at the documentation it indicates that you can pass the value null
for the version. 查看文档,它表示您可以为该版本传递null
值。 This will override default behaviour and remove the query string. 这将覆盖默认行为并删除查询字符串。
wp_enqueue_script('myjs', $pluginpath . 'build/js/app.min.js', array('jquery'), null);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.