Knowing which scripts are loaded with runat server

Discussion about how to code things with Jaxer.

Moderator: Aptana Staff

Knowing which scripts are loaded with runat server

Postby jburke » Tue Feb 26, 2008 5:45 am

Is there a Jaxer API that exposes the file names of any scripts that have been loaded on the server side?

I am asking because I am getting the Dojo JavaScript toolkit to work in Jaxer, and one of the things it does is find the script tag that loads dojo.js, and loads other scripts based on that path.

In client-side javascript, I can do a document.getElementsByTagName("script") to get the list of scripts. Is there something equivalent on the server side to get script file names loaded by Jaxer?
jburke
 
Posts: 4
Joined: Tue Feb 26, 2008 5:38 am

Postby davey » Tue Feb 26, 2008 6:23 pm

We dont have an explicit API for that currently, although the data likely exists at some point in the load process.

Look at this post by Tony Issakov, http://dojofindings.blogspot.com/2008/02/dojo-jaxer-updated-compatibility-block.html

It look like he's doing a similar thing, with a slightly different approach, he's loading a shim to manage the loading of the dojo.js but has a hard coded path in there to the location of the baseUrl for the dojo stuff.

as for document.getElementsByTagName that works fine server side.

Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <title>Untitled Document</title>
   </head>
   <body>
      
   <script id='script1' type="text/javascript" runat='server'></script>
   <script id='script2' type="text/javascript" runat='server'></script>
   <script id='script3' type="text/javascript" runat='server'></script>
   <script id='script4' type="text/javascript" runat='server'></script>
      
   <script id='mainScript' runat='server'>
      
      var scripts = document.getElementsByTagName('script');
      
      document.write(scripts.length)
      
   </script>
      
   </body>
</html>



the code block above returns references to 5 script elements. If you are using the Jaxer.load mechanism to load the scripts, you could easily wrap that up in a function to track the loads for you, or even try some aspect oriented javascript approach to add some tracking code to that method.
User avatar
davey
 
Posts: 710
Joined: Mon Jul 23, 2007 9:25 pm

Postby jburke » Tue Feb 26, 2008 7:02 pm

It looks like I can do a document.getElmentsByTagName("script") and get an array of script nodes. However, when I ask for scripts[i].getAttribute("src") I get null, even if there is a src attribute on the script tag. I also tried scripts[i].src, but that was also empty. That is the core of the problem: if I can get the src attribute value, then things will work out.

Note that doing scripts[i].getAttribute("runat") and scripts[i].getAttribute("type") do give proper values.

Thanks for the link to the blog -- I'm actually working jaxer support that will go into the dojo source. Right now, we can get it to work if you specify djConfig.baseUrl explicitly, but if I can get a property value for the script's src attribute, then folks will not need to do the explicit baseUrl config.
jburke
 
Posts: 4
Joined: Tue Feb 26, 2008 5:38 am

Postby klindsey » Tue Feb 26, 2008 9:24 pm

Hi jburke,

There is something strange going on there with document.getElementsByTagName. To get around that for now you can use "document.documentElement.getElementsByTagName("script")" and that should behave as you expect.

HTH,
Kevin Lindsey
Aptana, Inc. - http://www.aptana.com
User avatar
klindsey
 
Posts: 81
Joined: Thu Jul 13, 2006 6:28 pm
Location: Fort Worth, TX

Postby jburke » Tue Feb 26, 2008 10:28 pm

Kevin: Using document.documentElement.getElementsByTagName("script") does not seem to make a difference: still null for getAttribute("src") but other attributes like "runat" and "type" work correctly.

I am doing the getElementsByTagName call in the script that has the src value on it. I'm not sure if that is part of the issue. I do not think it is, since the other attributes report correctly for that script/tag.

I'm using Jaxer version 0.9.3.2156 (according to the version.txt file).

It looks like this bug was filed for the issue:
http://support.aptana.com/asap/browse/JXR-85

I'll continue to watch it. Thanks.
jburke
 
Posts: 4
Joined: Tue Feb 26, 2008 5:38 am

Postby usguest » Fri Feb 29, 2008 9:58 pm

You might also want to check out Kris Zyp's work on getting Jaxer and dojo to work closer:

http://www.sitepen.com/blog/2008/02/29/ ... lkits-dtl/

We'll be working with them and with you in the community to make this more seamless. Your inputs are much appreciated.
usguest
 
Posts: 94
Joined: Fri Mar 02, 2007 6:13 pm

Postby usguest » Tue Mar 11, 2008 11:20 pm

We'll be releasing Jaxer 0.9.5 very shortly which does not inline scripts that have a ser- or both-type runat and an external src. That should solve this problem you're seeing. Please let us know if it does not: http://support.aptana.com/asap/browse/JXR-85
usguest
 
Posts: 94
Joined: Fri Mar 02, 2007 6:13 pm


Return to Jaxer Coding Q & A