snipt

Ctrl+h for KB shortcuts

Text only

Load jQuery from Google CDN , or load from your site if it's not available!

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script><script>window.jQuery || document.write('<script src="http://website.com/js/jquery-1.8.2.min.js"><\/script>')</script>
https://snipt.net/embed/877a66c9a0c13e0799d70ddb40d7474e/
/raw/877a66c9a0c13e0799d70ddb40d7474e/
877a66c9a0c13e0799d70ddb40d7474e
text
Text only
1
2019-02-13T20:13:47
True
False
True
Feb 12, 2014 at 12:21 PM
/api/public/snipt/113085/
load-jquery-from-google-cdn-or-load-from-your-site-if-its-not-available
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>&lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js&quot;&gt;&lt;/script&gt;&lt;script&gt;window.jQuery || document.write(&#39;&lt;script src=&quot;http://website.com/js/jquery-1.8.2.min.js&quot;&gt;&lt;\/script&gt;&#39;)&lt;/script&gt; </span></pre></div> </td></tr></table>
cdn, jquery

HTML

Jquery from CDN or local

1
2
3
4
<!-- Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="<?php echo js_path(); ?>jquery-1.7.2.min.js"><\/script>')</script>
https://snipt.net/embed/b686461cfff5315cce4cbf89b77d3468/
/raw/b686461cfff5315cce4cbf89b77d3468/
b686461cfff5315cce4cbf89b77d3468
html
HTML
4
2019-08-15T12:31:23
True
False
False
Oct 21, 2013 at 02:45 PM
/api/public/snipt/89116/
jquery-from-cdn-or-local
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c">&lt;!-- Grab Google CDN&#39;s jQuery, with a protocol relative URL; fall back to local if offline --&gt;</span> </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a><span class="p">&lt;</span><span class="nt">script</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">script</span><span class="p">&gt;</span> </span><span id="L-4"><a name="L-4"></a><span class="p">&lt;</span><span class="nt">script</span><span class="p">&gt;</span><span class="nb">window</span><span class="p">.</span><span class="nx">jQuery</span> <span class="o">||</span> <span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="s1">&#39;&lt;script src=&quot;&lt;?php echo js_path(); ?&gt;jquery-1.7.2.min.js&quot;&gt;&lt;\/script&gt;&#39;</span><span class="p">)&lt;/</span><span class="nt">script</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
cdn, fallback, jquery, local

PHP

Load jQuery from Google CDN on Wordpress

1
2
3
4
5
6
7
8
function jquery_cdn() {
   if (!is_admin()) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.3');
      wp_enqueue_script('jquery');
   }
}
add_action('init', 'jquery_cdn');
https://snipt.net/embed/1812127ed64a523ea15b42170b5248ae/
/raw/1812127ed64a523ea15b42170b5248ae/
1812127ed64a523ea15b42170b5248ae
php
PHP
8
2016-11-27T00:41:43
True
False
True
Mar 05, 2013 at 09:26 AM
/api/public/snipt/57037/
load-jquery-from-google-cdn-on-wordpress
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a> <a href="#L-7">7</a> <a href="#L-8">8</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="x">function jquery_cdn() {</span> </span><span id="L-2"><a name="L-2"></a><span class="x"> if (!is_admin()) {</span> </span><span id="L-3"><a name="L-3"></a><span class="x"> wp_deregister_script(&#39;jquery&#39;);</span> </span><span id="L-4"><a name="L-4"></a><span class="x"> wp_register_script(&#39;jquery&#39;, &#39;http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js&#39;, false, &#39;1.8.3&#39;);</span> </span><span id="L-5"><a name="L-5"></a><span class="x"> wp_enqueue_script(&#39;jquery&#39;);</span> </span><span id="L-6"><a name="L-6"></a><span class="x"> }</span> </span><span id="L-7"><a name="L-7"></a><span class="x">}</span> </span><span id="L-8"><a name="L-8"></a><span class="x">add_action(&#39;init&#39;, &#39;jquery_cdn&#39;);</span> </span></pre></div> </td></tr></table>
cdn, functions.php, javascript, jquery, php, wordpress

HTML

jQuery on Google CDN

<!-- all cdn links can be found on http://scriptsrc.net/ -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
https://snipt.net/embed/2aa2390a82779f69407b0befcd1275b1/
/raw/2aa2390a82779f69407b0befcd1275b1/
2aa2390a82779f69407b0befcd1275b1
html
HTML
3
2019-08-14T07:54:26
True
False
False
/api/public/snipt/20600/
jquery-on-google-cdn
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c">&lt;!-- all cdn links can be found on http://scriptsrc.net/ --&gt;</span> </span><span id="L-2"><a name="L-2"></a><span class="p">&lt;</span><span class="nt">script</span> <span class="na">type</span><span class="o">=</span><span class="s">&quot;text/javascript&quot;</span> <span class="na">src</span><span class="o">=</span><span class="s">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js&quot;</span><span class="p">&gt;&lt;/</span><span class="nt">script</span><span class="p">&gt;</span> </span></pre></div> </td></tr></table>
cdn, jquery