最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to load local files if CDN is not working - Stack Overflow

programmeradmin5浏览0评论

I am using some CDN js and css files.

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

i found a good link written like this

<script class="jsbin" src=".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. 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=".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 .

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

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

Please help

Thanks in advance

I am using some CDN js and css files.

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

i found a good link written like this

<script class="jsbin" src="http://ajax.googleapis./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. 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./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 .

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

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

Please help

Thanks in advance

Share Improve this question edited Apr 18, 2013 at 7:53 user1926138 asked Apr 18, 2013 at 7:46 user1926138user1926138 1,5149 gold badges34 silver badges54 bronze badges 2
  • 2 It's not the CDN's problem. You have two different local paths. – ahren Commented Apr 18, 2013 at 8:02
  • i have written two local path but i want to do like Example: if x cdn is not working then it will download only the x.local not others. if 2 cdn js are not working then it will download only 2 not all how to do this – user1926138 Commented Apr 18, 2013 at 9:04
Add a ment  | 

2 Answers 2

Reset to default 14

You can use this scripts below:

<script src="//ajax.googleapis./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./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.

Basically you are trying to do failover between CDN and your origin server. If CDN fails, the request fails over to your origin server. One option is to use DNS level failover with primary to CDN CNAME, backup to your origin server hostname.

And you also include healthcheck in your DNS setup for both CDN and origin server. Once healthcheck fails for CDN, DNS should fail over to your origin server and serve static file from there automatically.

发布评论

评论列表(0)

  1. 暂无评论