如果CDN不工作,如何加载本地文件 [英] How to load local files if CDN is not working

查看:69
本文介绍了如果CDN不工作,如何加载本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一些CDN js和css文件。

I am using some CDN js and css files.

我在Google中搜索了如果CDN无法正常工作,如何加载本地数据。

I searched in Google that how to load local data if CDN is not working.

我发现这样的好链接

<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script type="text/javascript">
            if (typeof jQuery == 'undefined') {
                document.write(unescape("%3Cscript src='JS/Plugins/jquery-1.8.2.min.js' type='text/javascript'%3E%3C/script%3E"));
            }
        </script>

是的,它的工作,但后来我尝试了另一个CDN网络,然后它不从本地下载。如果CDN不工作,那么它在我的页面中显示错误,并且由于缺少该js文件,页面无法正常工作。
表示:

Yes its working but then i tried for another CDN network ,then its not downloading from local. if the CDN is not working then it is showing error in my page and the page is not working properly due to that missing that js file. means :

<script type="text/javascript" src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script type="text/javascript">
    if (typeof jQuery == 'undefined') {
        document.write(unescape("%3Cscript src='Include/JS/JqueryPlugin/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
    }
</script>

在上述情况下,当上述CDN不工作时本地jquery.min.js没有下载。

in the above case the local jquery.min.js is not downloading when the above CDN is not working .

同样如何处理CSS(在谷歌搜索并找不到任何好的解决方案)。

similarly how to do for CSS(searched in Google and not found any good solution).

如何知道哪个CDN不起作用并从本地下载相应的文件。

How to do know which CDN is not working and download respective files from local.

请帮助

提前致谢

推荐答案

您可以使用以下脚本:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>    window.jQuery || document.write('<script src="/scripts/jquery.1.9.1.min.js"><\/script>')</script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<script>    window.jQuery.ui || document.write('<script src="/scripts/jquery-ui.min.js"><\/script>')</script>

希望有用!

这篇关于如果CDN不工作,如何加载本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆