为什么 WordPress 在使用 wp_register_script() 时放置“text/rocketscript”而不是“text/javascript”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9681032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why is WordPress placing "text/rocketscript" instead of "text/javascript" when using wp_register_script()?
提问by Tabrez Ahmed
I inserted the following code in a WordPress plugin:
我在WordPress 插件中插入了以下代码:
wp_deregister_script('jquery');
wp_register_script('jquery', "http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
wp_enqueue_script('jquery');
The following is echoed to the browser:
以下回显到浏览器:
<script type='text/rocketscript' data-rocketsrc='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js?ver=3.3.1'></script>
Instead of:
代替:
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
I don't know what is happening. Perhaps wp_register_script()
is supposed to work in this way. I also testedif any jQuery code worked on the client sidebut it didn't.
我不知道发生了什么。也许wp_register_script()
应该以这种方式工作。我还测试了是否有任何 jQuery 代码在客户端工作,但没有。
采纳答案by Emir Akayd?n
Probably one of wordpress plugins is using CloudFlare
.
可能是 wordpress 插件之一正在使用CloudFlare
.
https://support.cloudflare.com/hc/en-us/articles/200168056-What-does-Rocket-Loader-do-
https://support.cloudflare.com/hc/en-us/articles/200168056-What-does-Rocket-Loader-do-
Try disabling all the plugins and re-enabling them one by one to find out which one is causing this issue. It's not a problem actually.
尝试禁用所有插件并一一重新启用它们,以找出导致此问题的原因。其实这不是问题。
回答by Frank
It is easy to fix.
很容易修复。
You must change the following tag: <script type="text/javascript"></script>
您必须更改以下标签: <script type="text/javascript"></script>
add: data-cfasync="false"
添加: data-cfasync="false"
example:
例子:
<script data-cfasync="false" type="text/javascript"></script>
回答by Damon Billian
Rocket Loader is not included in any WordPress plugins. You would have to disable Rocket Loader by going to: settings->CloudFlare settings (Performance Settings)->Rocket Loader->Toggle Off (this feature is optional and has to be turned on).
Rocket Loader 不包含在任何 WordPress 插件中。您必须通过以下方式禁用 Rocket Loader:设置->CloudFlare 设置(性能设置)->Rocket Loader->Toggle Off(此功能是可选的,必须打开)。
回答by Aboobacker P
I was facing this issue with
我正面临这个问题
WP Rocketplugin which was adding type='text/rocketscript'
to the script tags.
添加type='text/rocketscript'
到脚本标签的WP Rocket插件 。
Fixed it by adding
通过添加修复它
data-cfasync="false"
data-cfasync="false"
to the script tags.
到脚本标签。