Good day! The problem is that on the Blogger platform it is not always possible to insert JavaScript into the template html, I used hosting on People for such scripts before. The people are a wonderful hosting, but for the last 5 days it was not available, it means that javascript 's did not work in my blogs and blogs of my readers. This situation could not suit me, and now I have uploaded the scripts to my paid hosting.

So, there is hostA and hostB on both of them MyScript.js now in Blogger'а html Blogger'а is a record

 <script src='http://hostA/MyScript.js'/> 

How to modify it so that the hostA inaccessible script was taken from the hostB ?

Thank.

  • Either arrange the scripts so that they check whether they are not loaded themselves, or to do something like a router on their stable hosting - the download from host3 will happen in html and the server will go to host3 on all possible hosts and return from the first successful one. - Chad
  • one
    If I were you, I would place all the statics on Amazon S3 and forget about all kinds of "peoples", like a bad dream. - Ilya Pirogov
  • Thank! The people, in general, not so bad since 2007, this is his first misfire. If I only had bits of static in addition to the “people”, I would add Amazon ... But I have a little more serious needs, that's why we have hosting on hostgator and also in Iceland. So we have enough hosting services, I just didn’t expect problems from the people, so I didn’t bother “until thunder struck” :(. - svetlana0777

2 answers 2

Well, for example, put two links to the script in a row, first from the left host, then to your
in javascript on the left host, declare a variable, for example var hostA = true; .

In the soon script, check the presence of this variable, if it exists, then the script 1 has loaded and the second one does not need to be loaded, otherwise we will load.

  • 2
    > Well, for example, put two links to the script in a row, first from the left host, then to your own So then both scripts will always be loaded. - Ilya Pirogov

You can probably try another option through jquery for example:

 <script type="text/javascript"> $.ajax({url:"http://hostA/script.js", dataType:"script"}) .fail(function(){ $.ajax({url:"http://hostB/script.js", dataType:"script"}); }); </script> 

If you need to load Html js s at the moment of loading, you need to add async:false to the ajax request, otherwise we can start using the script before it loads (if you expect a similarity of the <script> tag)