link mode

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

test it now

page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<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=http://noteslog.com/personal/projects/" id="g8n"></script>
<script type="text/javascript" src="link/script1.js"></script>
<script type="text/javascript" src="link/main.js"></script>
</head>
<body>
<p><a href="javascript:alert( 
goon['http://noteslog.com/personal/projects/goon/1.1/link/main.js']
.exported.msg 
);">test goon</a></p>
<p><a href="javascript:alert( 
goony.msg 
);">test goony</a></p>
</body>
</html>

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.

 

link.png

link2.png

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.

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