Free Hosting Tricks #1

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Here is a little trick I came up with some time ago to compensate for flaky hosting, thankfully have not needed it for a while but some of you may find this useful for basic sites. However if you are heavily dependant on databases then it gets a lot more complicated as these may need to be synchronised periodically or even frequently if you have a forum or chatroom.


How it Works:
Basically you employ a Google Free Site as your main landing site, this runs a simple bit of javascript wrapped in XML. A quick check is performed to see if your actual site is up and running and if not performs a redirect to an alternate URL. This can either be a mirror copy of your site or just an error page, hosted on a different server/provider.

The check to see if a domain is up and running is very basic, using a simple request for an image. Should this image request fail it sends an error back to the javascript that asks for that same image from the next mirror site in turn and so on till it finds a working server.

When it finds one that works it then performs a redirect to the active host. Finally you need to add 'frame breakout' to the landing URL page in order to destroy the Google Site Iframe and hey presto your done.


Here's the basic XML code to be attached to a google web site page, modify to suit.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="test1" />
<Content type="html"><![CDATA[

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>


<script type="text/javascript">

var fields1="http://www.mySite_1/";                //primary site
var fields2="http://www.mySite_2/";                //secondary 
var fields3="http://www.mySite_3/";                //tertiary



function redir1(com)
{                                                   // read the command attribute
if (com == 1)sp=0;                            // check primary & set status : 0 = offline
if (com == 2)ss=0;                            // check secondary
if (com == 3)st=0;                            // check tertiary




if (com = "dump"){                                  // read the command attribute
//
winloc = fields1;                                     // sets default primary site
if (sp == 0)winloc=fields2;                        // if primary offline redirect to secondary site 
if (sp == 0 && ss == 0)winloc=fields3;        // if primary and secondary offline redirect to tertiary site 

window.location= winloc;                    // perform redirect

}// end dump

}// eof

</script>

</head>

<body>


<img src="http://www.mySite_1/test.gif" onerror="redir1(1)">    <!-- primary site check -->

<img src="http://www.mySite_2/test.gif"  onerror="redir1(2)">    <!-- secondary site check -->

<img src="http://www.mySite_3/test.gif"  onerror="redir1(3)">    <!-- tertiary site check -->

<script type="text/javascript">redir1(dump);</script>  <!-- initiate redirect  -->

</body>
</html>
]]></Content>
</Module>

Limitations:
Google is of course just like any other web host and can suffer from outages themselves but for the most part are regarded as very stable and ideal for this purpose.
 

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Good question.

Once you set up an account with Google and created your blank site.
Open the page editor.. and find the big button marked 'More actions' (it's on the far right)

More Actions -> Manage Site -> Attachments-> gives you the browse your PC for the upload


Now go back and look for the tab marked insert (far left of screen) click this and long list of options appears. The one you want is all the way down at the bottom marked more gadgets... Click that and a new window appears in that is box marked add gadget by url
this needs the full URL name of your site and the name of the XML gadget file eg: https://sites.google.com/site/smithjones/gadget.xml

click OK and the gadget appears on your web page
 

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Coming soon.. Secure password protection using Javascript
 

sankalpgarud98

New Member
Messages
108
Reaction score
0
Points
0
Nice idea mate. Thoroughly appreciate your effort.
Free hosting has its problems many a times, so such thing might help..
anyways,
cheers.
 

Interscopia

x10 Caffeine Addict
Prime Account
Messages
180
Reaction score
3
Points
18
Nice tutorial! Very descriptive. I might have to try this out.
 

Hoobrum

Member
Messages
60
Reaction score
1
Points
8
Great idea, but not all browser support onerror if I'm not mistaken.
 

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Thanks for the feedback Hoobrum, can confirm it works for latest FF but alas not IE9.
Will look at revising the script later in the week, if anybody else wants to try by all means do so.


Pondering the possabilities...
  • Onreadystatechange might work but 100% sure
  • vaugely recall IE had a special event handler ImageLoadFailed?
  • Generating the 'status' variable using a remote JS script from the site being checked rather than looking for the image load error.. maybe
  • Use Google apps engine with Python or Java.... uuugh
  • Beat it to death with a Yahoo Pipe.. tempting but would be ugly
  • Use FLASH / actionscript... aaagh I hate writing that stuff lol!
 
Last edited:

cybrax

Community Advocate
Community Support
Messages
764
Reaction score
27
Points
0
Update: scratch previous ramblings, have horibble feeling it's not the event handling but IE not accepting the redirect using window.location
 
Top