Forcing .src to the "right" server

Discussion in 'Javascript' started by Csaba Gabor, Mar 19, 2005.

  1. Csaba Gabor

    Csaba Gabor Guest

    The situation is simple, but I can't figure out a compact
    summary so please bear with me:

    I have a page wherein the src of a <script src="jsLibSomeName.js">
    MUST be run through my apache server (because it gets
    redirected to a .php file which is really spitting out the .js).

    There are, therefore, 3 situations that I see:
    1. Invoking the page externally
    2. Invoking the page via localhost or similar
    3. Invoking the page by double clicking it

    If the invoking is from 1 or 2, apache sees that the jsLib*
    ..js file is being sought and does a (302) redirect
    and this is working nifty. The line below is an example
    from my httpd.conf (apache configuration file) of how the
    localhost version works.

    RewriteRule (^|/)jslib/?([^/]+).js$ http://localhost/jsLib.php?name=$2 [NC,L]

    In scenario 3, however, IE or FF is looking for file:///....
    It's not going to the server! Simple, you say, just
    have the src be like src="http://YourDomain.com/jsLibOut.js"
    The problem with that, though, is that if I am (A) disconnected
    from the internet or (B) don't have a domain name active
    (because maybe I don't have a static IP just now) or (C)
    DNS servers are out of kilter cause maybe that dynamic IP
    just changed, then I'm stuck waiting forever in 2 and 3

    So it seems that I can't set a fixed src to force being
    passed efficiently through my Apache web server in all situations.

    So my question (drumroll, please, what everyone's been
    waiting for) is: What is the cleanest way to set this up
    so I can develop locally, but have availability globally
    in a seamless way? Seamless to me, that is - I don't
    want to think about this construct once I've set it up.


    Thanks for any ideas,
    Csaba Gabor from Vienna


    The following idea works with IE, but I can't use Firefox
    (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=286809):
    Immediately change the href on the <BASE href=...> if
    I am on localhost or file:///

    Here's how it looks:
    <html><head><base>
    <script type='text/javascript'>
    // next statement changes the BASE href in FF and IE, but only IE takes note
    if (location.protocol=="file:")
    document.getElementsByTagName('BASE')[0].href =
    "http://localhost";
    </script>
    ....
    <script type='text/javascript' src='jsLibOut.js'></script>
    Csaba Gabor, Mar 19, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Richter

    <txt src= ...> equivalent of <img src= ...>

    Steve Richter, Feb 8, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    2,066
    Laurent Bugnion
    Feb 9, 2006
  2. Greg Johnson
    Replies:
    4
    Views:
    3,054
  3. Replies:
    1
    Views:
    1,607
    Alex Hunsley
    Mar 23, 2007
  4. pheadxdll
    Replies:
    16
    Views:
    3,621
    Neredbojias
    Jun 6, 2007
  5. Soren Vejrum
    Replies:
    4
    Views:
    538
    Lasse Reichstein Nielsen
    Jul 5, 2003
Loading...

Share This Page