简体   繁体   English

如果CDN不工作,如何加载本地文件

[英]How to load local files if CDN is not working

I am using some CDN js and css files. 我正在使用一些CDN js和css文件。

I searched in Google that how to load local data if CDN is not working. 我在谷歌搜索了如果CDN无法正常工作,如何加载本地数据。

i found a good link written like this 我发现了一个像这样的好链接

<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>

Yes its working but then i tried for another CDN network ,then its not downloading from local. 是的,它的工作,但后来我尝试了另一个CDN网络,然后它不从本地下载。 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. 如果CDN不工作,那么它在我的页面中显示错误,并且由于缺少该js文件,页面无法正常工作。 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>

in the above case the local jquery.min.js is not downloading when the above CDN is not working . 在上面的例子中,当上述CDN不工作时,本地jquery.min.js没有下载。

similarly how to do for CSS(searched in Google and not found any good solution). 类似地如何做CSS(在谷歌搜索,没有找到任何好的解决方案)。

How to do know which CDN is not working and download respective files from local. 如何知道哪个CDN不起作用并从本地下载相应的文件。

Please help 请帮忙

Thanks in advance 提前致谢

You can use this scripts below: 您可以使用以下脚本:

<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>

Hope usefull! 希望有用!

This is achievable through DNS setting without changing code. 这可以通过DNS设置实现,而无需更改代码。

Basically you are trying to do failover between CDN and your origin server. 基本上,您尝试在CDN和源服务器之间进行故障转移。 If CDN fails, the request fails over to your origin server. 如果CDN失败,请求将故障转移到您的源服务器。 One option is to use DNS level failover with primary to CDN CNAME, backup to your origin server hostname. 一种选择是将DNS级别故障转移与主要CDN CNAME一起使用,备份到源服务器主机名。

And you also include healthcheck in your DNS setup for both CDN and origin server. 此外,您还在CDN和源服务器的DNS设置中包含了healthcheck。 Once healthcheck fails for CDN, DNS should fail over to your origin server and serve static file from there automatically. 一旦健康检查因CDN而失败,DNS应该故障转移到您的源服务器并自动从那里提供静态文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM