如何在Wordpress中添加最初从internet加载的备份javascript文件

如何在Wordpress中添加最初从internet加载的备份javascript文件,wordpress,backup,Wordpress,Backup,我相信你们都知道从谷歌下载jquery之类的文件。我正试图加载一个类似的文件,但我想在我的服务器上备份该文件,以防在线版本关闭,我不知道如何在Wordpress中进行备份 下面是我目前从url加载的内容 wp_deregister_script('html5shiv'); wp_register_script('html5shiv', ("http://html5shim.googlecode.com/svn/trunk/html5.js"),false); wp_enqueue_script(

我相信你们都知道从谷歌下载jquery之类的文件。我正试图加载一个类似的文件,但我想在我的服务器上备份该文件,以防在线版本关闭,我不知道如何在Wordpress中进行备份

下面是我目前从url加载的内容

wp_deregister_script('html5shiv');
wp_register_script('html5shiv', ("http://html5shim.googlecode.com/svn/trunk/html5.js"),false);
wp_enqueue_script('html5shiv');

我不熟悉Wordpress排队系统,但这里有一些javascript的常规代码,其中包含回退功能。您可能希望将此问题张贴在WP api问题往往得到更好答案的位置。这里有一个后备机制

//add a property to the window object in foo.js
window.banana = 'peeled';

<head>
  <script src="https://mysite.com/foo.js" type="text/javascript"></script>

  <script type="text/javascript">    
    //fallback mechanism if not available    
    if (!window.Banana) { document.write(unescape("%3Cscript src='/localfoo.js' type='text/javascript'%3E%3C/script%3E")); }

  </script>
</head>
//向foo.js中的窗口对象添加属性
window.banana='去皮';
//回退机制(如果不可用)
如果(!window.Banana){document.write(unescape(“%3Cscript src=”/localfoo.js'type='text/javascript'%3E%3C/script%3E”);}
我想这就是你要找的

C&p,以防有人稍后回来查找此网站,但该网站不可用:

<?php
$url = 'http://ajax.googleapis.com/ajax/libssss/jquery/1.6.4/jquery.min.js'; // the URL to check against
$test_url = @fopen($url,'r'); // test parameters
if($test_url !== false) { // test if the URL exists
    function load_external_jQuery() { // load external file
        wp_deregister_script( 'jquery' ); // deregisters the default WordPress jQuery
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js'); // register the external file
        wp_enqueue_script('jquery'); // enqueue the external file
    }
    add_action('wp_enqueue_scripts', 'load_external_jQuery'); // initiate the function
} else {
    function load_local_jQuery() {
        wp_deregister_script('jquery'); // initiate the function
        wp_register_script('jquery', bloginfo('template_url').'/js/libs/jquery-1.6.1.min.js', __FILE__, false, '1.6.4', true); // register the local file
        wp_enqueue_script('jquery'); // enqueue the local file
    }
add_action('wp_enqueue_scripts', 'load_local_jQuery'); // initiate the function
}
?>


在阅读之前帖子链接中的评论时,我在这里遇到了与此类似的@mariusmilliunas-我会使用客户端解决方案,而不是服务器端解决方案。这只检查jQuery库是否可用于服务器,而不是客户端。像伊朗这样的地方阻止了对谷歌CDN的访问,所以你的网站无法为他们服务。也许伊朗不是你典型的访客,但我想你明白我的意思了。