1

Scenario:

I'd like to load the jQuery and jQuery UI lib from Google's CDN but if they take too long to load, then retrieve it from the local web server.

I'm using Coldfusion but I don't think that is the answer. I think I need to do something with JavaScript.

I wrapped my script src tags with cftry but that did not work.

<cftry>
    <!-- Load Jquery from Google -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/<cfoutput>#css_style#</cfoutput>/jquery-ui.css" type="text/css" media="all" />
    <cfcatch type="any">
        <!-- load from local server -->
        <script src="assets/jQuery/jquery-1.7.2.min.js"></script>
        <script src="assets/jQueryUI/js/jquery-ui-1.8.7.custom.min.js"></script>
        <link rel="stylesheet" href="assets/jQueryUI/css/<cfoutput>#css_style#</cfoutput>/jquery-ui-1.8.7.custom.css" type="text/css" media="all" />
        </cfcatch>
</cftry>
4

2 に答える 2

6
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js"></script>
<script type="text/javascript">window.jQuery || document.write("<script type='text/javascript' src='js/jquery-1.8.3.min.js'>\x3C/script>")</script>

-- corrected mixed quotes in statement. Dreamweaver reported a syntax error until that was corrected --

于 2012-04-26T14:07:34.073 に答える
0
<script>
setTimeout(function() {
  if(window.jQuery) return;
  var n = document.getElementsByTagName("script")[0];
  n.parentNode.insertBefore(document.createElement("script"), n).src = "assets/jQuery/jquery-1.7.2.min.js";
}, 5000);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
于 2012-04-26T14:16:35.683 に答える