Hermes - Dynamic Script Attachment Allows Cross-Domain Communication

M

michaeloder

I was working on a project recently in which a client needed to
include check content entered by a user on one site against a database
hosted on a different site under a different domain. The ideal
solution was AJAX but that was ruled out because of the cross-domain
issue. Iframes would have worked for displaying the result but would
have been very clunky and would allow any client-side processing of
the data on the original site. Script inclusion could include the
remote data but wouldn't be dynamic plus it has the added risk that if
the foreign server is unavailbale Internet Explorer will not show the
original page at all.

I came up with the idea of dynamically adding script tags to the
document to get around this limitation. Checking around a I found a
couple of sites that implemented the technique, but I had never heard
of it before. Considering that this techniques provides a simpe but
effective method of cross-domain communiction, I would have thought it
would have been a common item in JavaScript developers' toolkits. To
provide a simpler name for people to reference than Dynamic Script
Attachment, I propose naming the technique Hermes after the Greek
messenger of the Gods.

For a code samples and an explanation of the technique see:
http://www.tomorrownext.com/hermes/

For a variety of simple demos see:
http://www.tomorrownext.com/hermesdemo/

Let me know what you think.
 
R

Randy Webb

(e-mail address removed) said the following on 2/20/2007 9:58 PM:
I was working on a project recently in which a client needed to
include check content entered by a user on one site against a database
hosted on a different site under a different domain. The ideal
solution was AJAX but that was ruled out because of the cross-domain
issue.

I can think of more "ideal solutions" than AJAX and for more reasons
than just cross-domain issues.
Iframes would have worked for displaying the result but would
have been very clunky and would allow any client-side processing of
the data on the original site. Script inclusion could include the
remote data but wouldn't be dynamic plus it has the added risk that if
the foreign server is unavailbale Internet Explorer will not show the
original page at all.

If a remote server isn't available for an IFrame then IE won't show the
parent page? Never run into that one before but never been a big fan of
IFrames either.
I came up with the idea of dynamically adding script tags to the
document to get around this limitation. Checking around a I found a
couple of sites that implemented the technique, but I had never heard
of it before.

All you had to do was ask here :)
Considering that this techniques provides a simpe but effective
method of cross-domain communiction, I would have thought it
would have been a common item in JavaScript developers' toolkits.

It is so common in my toolkit that I don't even have an AJAX approach in
my bag of tricks.
To provide a simpler name for people to reference than Dynamic Script
Attachment, I propose naming the technique Hermes after the Greek
messenger of the Gods.

I call it "Dynamic Script Insertion" because you are inserting a script
block, not attaching it. As for a name, I propose "HikkScript" as I have
been dynamically inserting script elements since NN4 was still a popular
browser.
layerRef.open();
layerRef.document.write(<'script....><\/script>');
layerRef.close();

(Try it, it works.)
For a code samples and an explanation of the technique see:
http://www.tomorrownext.com/hermes/

There are some things you can do that will make that script a little
better. Instead of using the HEAD element, create a div element, hide it
using CSS, and add/remove your script blocks from there. Makes tracking
them a lot simpler.
For a variety of simple demos see:
http://www.tomorrownext.com/hermesdemo/

Let me know what you think.

Search the archives for "loadJSFile Randy Webb" and you can read a lot
about it. There is also a thread entitled "createTextNode and IE7" that
is chock full of examples, thoughts, and references on doing what you
are doing.

"createTextNode and IE7"
<URL:
http://groups.google.com.au/group/c...amic+script+insertion&rnum=5#32362b99328a2adb
That thread will eventually lead you here:

<URL: http://members.aol.com/_ht_a/hikksnotathome/loadJSFile/index.html>

Which is a list of browsers and what does or does not work in those
browsers. If you have a browser that isn't listed and can post the
information for that browser, I would appreciate it so I can update the
page some more.

If you follow the thread above and the search and do some hard core
reading you can learn a lot about what you are doing, I just prefer the
name HikkScript to Hermes, has a personal ring to it :)
 
E

Evertjan.

Randy Webb wrote on 21 feb 2007 in comp.lang.javascript:
layerRef.document.write(<'script....><\/script>'); [..]
(Try it, it works.)

With the ....(<'script.... ???

;-}
 
M

michaeloder

(e-mail address removed) said the following on 2/20/2007 9:58 PM:


I can think of more "ideal solutions" than AJAX and for more reasons
than just cross-domain issues.


If a remote server isn't available for an IFrame then IE won't show the
parent page? Never run into that one before but never been a big fan of
IFrames either.


All you had to do was ask here :)


It is so common in my toolkit that I don't even have an AJAX approach in
my bag of tricks.


I call it "Dynamic Script Insertion" because you are inserting a script
block, not attaching it. As for a name, I propose "HikkScript" as I have
been dynamically inserting script elements since NN4 was still a popular
browser.
layerRef.open();
layerRef.document.write(<'script....><\/script>');
layerRef.close();

(Try it, it works.)


There are some things you can do that will make that script a little
better. Instead of using the HEAD element, create a div element, hide it
using CSS, and add/remove your script blocks from there. Makes tracking
them a lot simpler.



Search the archives for "loadJSFile Randy Webb" and you can read a lot
about it. There is also a thread entitled "createTextNode and IE7" that
is chock full of examples, thoughts, and references on doing what you
are doing.

"createTextNode and IE7"
<URL:http://groups.google.com.au/group/comp.lang.javascript/browse_frm/thr...

That thread will eventually lead you here:

<URL:http://members.aol.com/_ht_a/hikksnotathome/loadJSFile/index.html>

Which is a list of browsers and what does or does not work in those
browsers. If you have a browser that isn't listed and can post the
information for that browser, I would appreciate it so I can update the
page some more.

If you follow the thread above and the search and do some hard core
reading you can learn a lot about what you are doing, I just prefer the
name HikkScript to Hermes, has a personal ring to it :)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Thanks for the suggestion.

As you pointed out the technique has been used on occasion by
JavaScript developers for awhile, but it has not been commonly used or
known. The same was true of AJAX and COMET, but the awareness and
utilization of those techniques increased markedly once they acquired
a name.

Searching for "Dynamic Script Insertion" on Google yielded just 303
results. Search for "AJAX" yielded more than 67 million results and a
search for "Comet JavaScript" yielded 1.3 million results, so there is
a real lack of awareness of the technique. That is what I''m trying to
help address by posting about it and proposing a name. If another name
sticks, so be it, but I think greater knowledge of the technique could
be very helpful for the development community in general.

The comment about the page not loading in Internet Explorer was in
regard to standard script inclusion not iFrames.

By the way, I liked you Javascript Best Practices site.

-Mike
 
R

Richard Cornford

Searching for "Dynamic Script Insertion" on Google yielded
just 303 results.

The vast majority of which were pertinent to the subject.
Search for "AJAX" yielded more than 67 million results

How many about soccer teams, cleaning compounds and Greek heroes?
and a search for "Comet JavaScript" yielded 1.3
million results,

It is rarely helpful to stick "javascript" into a google search as far
too many pages include NOSCRIPT element which pointlessly tell the user
that they need javascript enabled, but which goggle sees as content.
so there is a real lack of awareness of the technique.

You have only demonstrated an absence of people talking about it using
those terms.
That is what I''m trying to
help address by posting about it and proposing a name.
<snip>

At the point of proposing the name we can be sure that no references to
"hermes" currently relate to script insertion. A goggle search currently
turns up 23,000,000 results for "hermes", which will not be going away
just because you want to attach the term to a particular scripting
technique.

Richard.
 
D

dd

I propose naming the technique Hermes after the Greek
messenger of the Gods.
Let me know what you think.

Sorry to disappoint your naming technique, but
it already has a popular name ... "dynodes". If
you google : javascript dynodes you'll find
numerous pages about how it's achieved. On the
search I just did I got 12,700 results for those
two keywords together.
 
R

Randy Webb

Richard Cornford said the following on 2/21/2007 6:08 PM:
<snip>

At the point of proposing the name we can be sure that no references to
"hermes" currently relate to script insertion. A goggle search currently
turns up 23,000,000 results for "hermes", which will not be going away
just because you want to attach the term to a particular scripting
technique.

"Hermes Script" gives 766,000 hits. Makes you wonder if a Google Search
for anything is good for anything.
 
R

Randy Webb

dd said the following on 2/22/2007 4:13 AM:
Sorry to disappoint your naming technique, but
it already has a popular name ... "dynodes".

Not sure it is a "popular name", but there is a better search to find it.
If you google : javascript dynodes you'll find
numerous pages about how it's achieved. On the
search I just did I got 12,700 results for those
two keywords together.

Google: Dynamic Script Insert and you get 994,000 hits. So "dynodes"
isn't such a great search criteria.
 
D

dd

Google: Dynamic Script Insert and you get 994,000 hits. So "dynodes"
isn't such a great search criteria.

Isn't that exactly why dynodes is a better search
term? It's LESS hits. I'd rather have 12,700 hits
on the word dynodes than 994,000 on a more generic
search that isn't necessarily relevant. The word
dynode(s) is totally relevant :)
 
D

Dr J R Stockton

In comp.lang.javascript message said:
"Hermes Script" gives 766,000 hits. Makes you wonder if a Google Search
for anything is good for anything.

Well, today I wanted to know whether a NASA/Montana web document seen at
Montana had a copy in NASA proper. An exact search on a particular
sentence found initially just Montana, and including "similar" found
three copies at uninteresting locations. So I now know that there is no
copy at NASA.

It's largely a matter of skill in formulating the search, and luck in
being able to do so. A search for "Randy Webb" gives 78,100 hits; one
for "John Stockton" gives 388,000; but +"John Stockton" -NBA gives just
168,000 -- and the first two entries might be recognised by those here.

A search including my middle name finds just one entry (not me), though
the name itself occurs in almost as many pages as "Randy".
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top