I thought it was a good idea at the time to point several of my domains to a single external Javascript file on one of my other domains. Problem is, today there is a router problem and that one domain is inaccessible. This means that my other domains don't load the part of the page following the external Javascript reference for ??? several seconds. The delay is long enough that it would discourage most users from staying on my sites.
Is there a way to work around this, so that if an external JS file is not available, the error is ignored and the rest of the page continues to load normally?
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
might be a good idea to mirror the javascript file so that its requested of the sites domain instead of a different domain, that way if there is a problem and the domains not available it doesn't slow the site down.
other than that - keep the size of the javascript small as practical
I don't think that there is any other way around, because a webbrowser will not know that the file is unavailable unless it requests the file and thats where your delay is coming from, the only way to prevent that is to not request the file at all ( or request it from the same domain where you're confident it can be loaded in a timely manner )
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Yeah ... I was afraid I would hear something like that! Rats ... Thanks for the feedback.
Moderator
From: Yorkshire, UK
Registered: 2006-08-19
Posts: 2862
I've been thanked 85 times.
Offline
If you still want to keep the js file on just one domain for easy maintenance, here's my suggestion
have a script on each domain that reads the remote file and caches it locally (once a day, for example). The logic in the script would be such that if the remote file couldn't be found then it the cached copy wouldn't be over written. Your other sites then look at their local cached copy
you still only ever need to change one file if ever you need to edit it
Hmm. Sounds like it might work ... Just think of the implications with every Adsense site out there if something happened to the Google network. Every page displaying Adsense would have the same problem. The cache idea wouldn't work with that, although it would with my problem.
You would think that the <Javascript> tag would have some kind of a 404 handler ...
Member
From: Pell City, Alabama USA
Registered: 2004-11-17
Posts: 2084
I've been thanked 5 times.
Offline
its not really a matter of handing a 404, if you were getting a simple 404 back your page would go ahead and load without the delay even thought the Javascript would still be missing and it might not look right. Your problem is that the browser is sitting there waiting to eventually timeout ( 408, 502, 504, etc... )
rather than try to script fetching the file from one domain and caching it on the others daily/weekly etc... Just put the file in one place and symlinks to it in your other domains webspaces. Be sure you allow Apache to follow symlinks
then you write and maintain your javascript in one place, and all your sites stay up to date and current. no need to script anything or copy files, and your javascript files gets served from the same domain so you can be sure if they can reach your site they can load your javascript file.
TombOfTheMutilated.NET - Destroying The Minds of America's Youth Since 2001
Only problem .... the domain the JS file is on is on a different server than all the domains calling it - along with the images. This was done to distribute the server load a bit more efficiently (but possibly a big mistake, in retrospect).
| Never |


