jQuery from Google CDN; fall back to WP local
-
Using the following to load Google’s CDN version of jQuery, then, for the few times when (and few countries where) Google is unavailable, fall back to the copy installed with WordPress. This works fine inserted in a doc’s
<head>
(inheader.php
, for instance):<!-- Grab Google CDN's jQuery; if that fails, fall back to WP local copy --> <?php wp_enqueue_script( 'jquery' ); ?> <script type="application/x-javascript">!window.jQuery && document.write('<script src="/wp-includes/js/jquery/jquery.js"><\/script>')</script>
In my
functions.php
I’ve de- and re- registered'jquery'
so it loads Google’s vers, as described in the codex: wp enqueue script. The<script>
line above is lifted from: HTML5 Boilerplate.One slight prob is if I put the
<script>
infooter.php
, the fall back fails. Otherwise, all seems to work well. So, I’m just wondering if anyone has a better solution, or sees some flaw in mine. Thanks.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘jQuery from Google CDN; fall back to WP local’ is closed to new replies.