标签: google-ajax-libraries

使用谷歌托管的jQuery的最佳方式,但回到我在谷歌上的托管库失败

尝试在Google(或其他Google托管的lib)上加载托管jQuery的好方法,但如果Google尝试失败,请加载我的jQuery副本?

我不是说谷歌是片状的.有些情况下谷歌副本被封锁(例如在伊朗).

我会设置一个计时器并检查jQuery对象吗?

这两份副本的危险是什么?

并不是真的在寻找"只使用谷歌"或"只使用自己的"等答案.我理解这些论点.我也理解用户可能会缓存Google版本.我正在考虑一般的云回退.


编辑:这部分补充......

由于Google建议使用google.load加载ajax库,并在完成后执行回调,我想知道这是否是序列化此问题的关键.

我知道这听起来有点疯狂.我只想弄清楚它是否可以以可靠的方式完成.


更新:jQuery现在托管在微软的CDN上.

http://www.asp.net/ajax/cdn/

jquery cdn google-ajax-libraries

1012
推荐指数
10
解决办法
15万
查看次数

从Google的CDN下载jQuery UI CSS

我打算使用谷歌为UI和Core下载jQuery lib.我的问题是,他们允许我为它下载CSS还是我必须自己托管它?

此外,如果我使用谷歌加载我应该如何加载其他插件?我可以将所有插件压缩在一起,还是应该是它自己的单独文件?

css jquery jquery-ui cdn google-ajax-libraries

453
推荐指数
6
解决办法
24万
查看次数

你在哪里包含jQuery库?谷歌JSAPI?CDN?

有几种方法可以包含jQuery和jQuery UI,我想知道人们在使用什么?

  • 谷歌JSAPI
  • jQuery的网站
  • 你自己的网站/服务器
  • 另一个CDN

我最近一直在使用Google JSAPI,但发现设置SSL连接需要很长时间,甚至只能解决google.com问题.我一直在谷歌使用以下内容:

<script src="https://www.google.com/jsapi"></script>
<script>
google.load('jquery', '1.3.1');
</script>
Run Code Online (Sandbox Code Playgroud)

我喜欢使用Google的想法,因此它在访问其他网站时被缓存并从我们的服务器节省带宽,但如果它一直是网站的缓慢部分,我可能会更改包含.

你用什么?你有什么问题吗?

编辑:刚刚访问过jQuery的网站,他们使用以下方法:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

编辑2:这是我去年包括jQuery没有任何问题的方式:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

不同的是删除http:.通过删除它,您不必担心在http和https之间切换.

javascript ssl jquery google-ajax-libraries

242
推荐指数
7
解决办法
28万
查看次数

实现从 Google AJAX 库 API 到本地 jQuery 的回退

在查看了使用 Google 的 AJAX 库 API 而不是在本地使用 jQuery 的优缺点之后,我看到有人在一个答案中写道(当然是在 Stack Overflow 上),可以通过以下方式解决 Google 的 API 有时会遇到的停机时间以某种方式退回到您使用的库的本地副本

我想在我的网站上使用 Google 的 AJAX 库 API,但我担心这种可能的停机时间,而且我很好奇如何实现这样的回退过程。

有没有人试过这样做?你能指出一些完成这样壮举的代码吗?

提前致谢。

jquery fallback cdn google-ajax-api google-ajax-libraries

5
推荐指数
1
解决办法
2115
查看次数

使用Google AJAX Libraries API时,将jQuery注入页面失败

我想使用Google AJAX Libraries API将jQuery注入页面,我提出了以下解决方案:

http://my-domain.com/inject-jquery.js:

;((function(){

  // Call this function once jQuery is available
  var func = function() {
    jQuery("body").prepend('<div>jQuery Rocks!</div>');
  };

  // Detect if page is already using jQuery
  if (!window.jQuery) {
    var done = false;
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement("script");
    script.src = "http://www.google.com/jsapi";
    script.onload = script.onreadystatechange = function(){

      // Once Google AJAX Libraries API is loaded ...
      if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {

        done = true;

        // …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-ajax-libraries

4
推荐指数
1
解决办法
9105
查看次数

适用于jQuery的Google AJAX Libraries CDN

我有一个页面,我需要SWFObject,jQuery和Google Maps API.我认为我可以使用以下好处:

<script type="text/javascript" src="http://www.google.com/jsapi?key=INSERT-YOUR-KEY"></script>
<script type="text/javascript">
    google.load("jquery", "1.4.1");
    google.load("swfobject", "2.2");
    google.load('maps', '2', {'callback': googleMapSetup });
</script>
Run Code Online (Sandbox Code Playgroud)

但是现在我在某处读到了(http://encosia.com/2008/12/10/3-reasons-why-you-should-let-google-host-jquery-for-you/)我需要使用

google.setOnLoadCallback(function() {
    // Place init code here instead of $(document).ready()
});
Run Code Online (Sandbox Code Playgroud)

而不是$(document).ready()..这是真的吗?

jquery document-ready google-ajax-libraries

4
推荐指数
1
解决办法
8380
查看次数

在Google Visualization API /带注释的时间线中自动重新缩放Y轴

当用户放大一系列日期时,有没有办法强制注释时间线图自动改变Y轴上的比例?

检查下面的示例,并注意2009-10-09的值("价格")比其他值大两个数量级.当用户放大时,例如2009-10-01 - 2009-10-08,Y轴不变(使图形相当无用).有没有办法自动重新缩放Y轴,以便在这个例子中它的范围从0到25或更合理(然后当用户缩小时当然回到默认值)?

示例:http://jsbin.com/ifogo

示例代码(与上面的链接相同):

<script src="http://www.google.com/jsapi"></script>
<div id="visualization" style="width: 800px; height: 400px;"></div>
<script>
google.load('visualization', '1', {packages: ['annotatedtimeline' ]});
function drawVisualization() {
  var data = new google.visualization.DataTable({
  cols: [{label: 'Date', type: 'date'}, {label: 'Price', type: 'number'}],
  rows: [
    { c:[{v: new Date(2009, 10, 1) }, {v: 11 }]},
    { c:[{v: new Date(2009, 10, 2) }, {v: 12 }]},
    { c:[{v: new Date(2009, 10, 3) }, {v: 13 }]},
    { c:[{v: new Date(2009, 10, 4) }, {v: …
Run Code Online (Sandbox Code Playgroud)

javascript google-visualization google-ajax-libraries

3
推荐指数
1
解决办法
2074
查看次数

加载第二个版本的 jQuery 和其他库

我正在制作一个由一段代码组成的小部件,用于放入您的网站,然后通过 js 获取内容。这是一个示例片段:

<div data-token="bc1cea6304e8" id="my-widget">
    <script src="http://localhost:8080/assets/eg-widget.js" type="text/javascript"></script>
</div>
Run Code Online (Sandbox Code Playgroud)

我正在做一个测试,检查页面是否已经有 jQuery,如果有,版本至少是 1.5。

if (typeof jQuery == 'undefined' || isVersion("1.5", ">")) {

    var script_tag = document.createElement('script');
    script_tag.setAttribute("type", "text/javascript");
    script_tag.setAttribute("src",
        "http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js");

    // Try to find the head, otherwise default to the documentElement
    (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);

    if (script_tag.readyState) {
        script_tag.onreadystatechange = function () { // For old versions of IE
            if (this.readyState == 'complete' || this.readyState == 'loaded') {
                scriptLoadHandler();
            }
        };
    } else { // Other browsers
        script_tag.onload = scriptLoadHandler;
    } …
Run Code Online (Sandbox Code Playgroud)

javascript jquery jquery-ui google-ajax-libraries

3
推荐指数
1
解决办法
2920
查看次数