link mode

To show the effect of the link mode, change a little the page already used in the Basic Example.

test it now


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title> link test </title>
<script type="text/javascript" src="goon-1.1.pack.js?base=" id="g8n"></script>
<script type="text/javascript" src="link/script1.js"></script>
<script type="text/javascript" src="link/main.js"></script>
<p><a href="javascript:alert( 
);">test goon</a></p>
<p><a href="javascript:alert( 
);">test goony</a></p>

If you open the above page in a browser, you’ll see an alert when each local script is being executed. The expected sequence is “script1”, “script2”, “script”, “main”. Deja-vue? Really it is. The expected sequence is the same as in the basic example, even if the execution is quite different.

Here “script1” is alerted because it’s directly loaded into the page, “script2” on the other hand is alerted because it’s required by script, which is required by main, which is directly loaded into the page. The script1 required by script before script2, is loaded in “link mode” because it was loaded before and no mode is explicitly specified, i.e. the loading is completely bypassed, and only a reference to the same object exported by the first script1 is exported to script. This can be easily verified by means of Firebug.




As you see, script1 has been loaded once, and its second entry in the goon repository is exporting exactly the same time exported by the first entry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.