【问题标题】:Google CDN for jquery or prototypejs or any other if not loaded用于 jquery 或 prototypejs 或任何其他(如果未加载)的 Google CDN
【发布时间】:2011-01-28 13:45:46
【问题描述】:

我在我的页面中使用 google CDN for jQuery 和 prototypeJS 库。出于任何原因,如果没有加载这些库,我可以采取什么措施使我的页面正常运行。

编辑

我在 SO 中找到了这个链接

Best way to use Google's hosted jQuery, but fall back to my hosted library on Google fail

这与我的问题非常相似。

很抱歉问了同样的问题。

【问题讨论】:

标签: jquery prototypejs google-cdn


【解决方案1】:

【讨论】:

  • 是 document.write 将脚本标签包含到 dom 的好方法吗?
【解决方案2】:
if (typeof jQuery == 'undefined')) {
  // Insert your local copy

  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = 'to/local/copy/jquery.js';

  var scriptHook = document.getElementsByTagName('script')[0];
  scriptHook.parentNode.insertBefore(script, scriptHook);

}

【讨论】:

  • 我应该把这段代码放在 google cdn 的 script 标签后面吗?
猜你喜欢
  • 2012-11-06
  • 2020-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-04
  • 1970-01-01
  • 2015-11-24
相关资源
最近更新 更多