# Friday, September 26, 2008

I have enough junk running on my development machine.  In an effort to try and keep my workstation speedy - I don't install any unnecessary services (Oracle server, Mapguide Server etc) on this machine.  In a larger development environment, running multiple servers on local development machines has a few other less than desirable results.  For example licensing issues and costs could increase, data management can become more complex, and just managing the extra services on N machines could cause a lot more work for your already overworked IT guy.

So instead I have centralized my server resources into a nice VM setup running on my beefy Dell server.  Now, regardless of which machine I use to develop I can still access the same data sets.  This is especially nice when traveling.  Specifically Mapguide Server and web tier are installed on my development web server.  When coding, I will either use my local IIS or the built in Visual Studio web server.  This poses one problem when working with Mapguide.  Referencing the web tier on the shared server from another web server will result in (XSS) errors.  Basically, javascript on one web server cannot access javascript code on another web server, which under most circumstances is a good thing.  When trying to develop using the Mapguide Web API on a central Mapguide server this poses a problem as the web tier API is wholly contained within the virtual directory on another server.  Gotta love when 'security' jumps up bites us in the behind.

The simple solution to this problem is to install the Mapguide web tier on every development machine.  This will require that each development machine have a web server installed, but chances are that is already the case.  When installing the web tier be sure to have the IP address of the Mapguide server handy as it will needed during the install.  Once the web tier is running locally, reference the local web tier in your URLs and the cross site scripting vulnerabilities go away!  If you're running the 64 Bit version of Vista on your development machine, check out my post installing the

Technorati Tags: ,
Friday, September 26, 2008 12:41:01 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |   |  Trackback
# Saturday, August 30, 2008

Javascript compression is something I had on my list for the next major release of RADE.  RADE is not quite ready for this step yet, so I thought I would give it a shot on Mapguide Enterprise and see what kind of results it would yield.  For a small site or an internal site this will probably not yield significant benefits.  However if you run a large public site javascript compression could squeeze out some more performance as well as save you on bandwidth costs.  Yahoo has a good article on .

I did some brief looking around and word on the internets is that the is one of the better compressors out there.  The YUI compressor is an open source java applet.   This *should* work with Mapguide Open, heck this might even be done already in MGOS - but I am only using Enterprise so I cannot confirm, deny, or test this.  

Some of the key things the compressor will do:

  1. remove all comments
  2. remove all white space and line breaks
  3. rename all local variables and parameters to single characters

The YUI compressor should not alter variable values or your logic in any way.

To use the YUI compressor you will need to .  Note that if you have the Oracle client installed, you probably have Java already  Once you have Java, you can download a copy of the (I'm going to start referring to it as the YC now...).  If you don't feel like downloading Java and the YC - I've attached the processed files at the bottom of this post.

Lets first look at the javascript shipped with Mapguide Enterprise.  If you browse to your web server extension viewer files (the default location is C:\Program Files\Autodesk\MapGuideEnterprise2009\WebServerExtensions\www\viewerfiles I believe) you will see ten javascript files.  If you choose to process these files on your own please back them up first.  Don't blame me if you don't backup your files and something goes wrong =).

Before YC:

Mapgude Enterprise Javascript before YUI Compression

Using the YC is simple:

   1: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\browserdetect.js browserdetect.js

 

Update the paths to Java and the YC as per your environment.  Using the handy dir /B *.js > go.bat I created a batch file of all the javascript files in the viewerfiles folder.  Be sure to run this from a dos window in the viewerfiles folder, or update the paths.  You will also need to create the comp folder in viewerfiles.   Quick cut and pasting created the following batch file:

   1: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\browserdetect.js browserdetect.js
   2: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\contextmenu.js contextmenu.js
   3: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\digitize.js digitize.js
   4: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\hashtable.js hashtable.js
   5: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\initdwfctrl.js initdwfctrl.js
   6: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\legend.js legend.js
   7: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\numfmt.js numfmt.js
   8: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\pngfix_map.js pngfix_map.js
   9: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\sarissa.js sarissa.js
  10: c:\oracle\product\10.2.0\client_1\jdk\bin\java.exe -jar f:\utils\YUICompress\yuicompressor-2.3.6\build\yuicompressor-2.3.6.jar -o comp\wz_jsgraphics.js wz_jsgraphics.js

 

(*Sorry about the overlap.  I'm working on a new layout and am addressing that in there)

Running that output all of the compressed of the files down somewhat, to pretty significantly.

Mapgude Enterprise Javascript After YUI Compression

A quick comparison of one of the function calls:

   1: function MenuData(menuName, arrowHeight, scrollInc, scrollDelay, minSize, iconScrollUp, iconScrollUpDisabled, iconScrollDown, iconScrollDownDisabled, owner, withIFrame, bkColor)
   2: function MenuData(F,H,I,K,E,G,D,J,A,C,B,L)

 

As you can see - the savings can be significant.

I'm not using the yet so I did not process those files, but I did check some of the JS in there and each script file had a huge header comment.  It looks like Fusion could also benefit from some compression action.  Please note, I've been running my web tier using this script for a day or two.  I've not run any serious testing on this code - so try this at your own risk.  You did make that backup I suggested, right?  That said, I have not personally experienced any problems yet.  Also, should you compress your viewerfiles and have problems be sure to try your backups.  Especially before calling your dealer or Autodesk for help. (sorry product support and ADN guys.  Please don't hate me =] ).

if you would rather not run the YC yourself.

Enjoy!

Friday, August 29, 2008 11:18:36 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |   |  Trackback
# Wednesday, July 30, 2008

Everyone knows there is a , right?  Well ok, maybe you didn't - but there is.  What that limit is depends on the browser.  There is a lot of conflicting information out there on the magical .  An RFC defines it, but no one really seems to pay attention to those anyhow.  (Are you listening Microsoft, of course you are! =]).  Anyhow, for IE, the query string length is usually around 2000 characters.

However, in most cases you're better off using a form and posting your data up to the server side that way, as the limitations on data are so large you will likely not need to worry about them.  Sometimes, query strings can also show your users just a little too much information - though I'm by no means a proponent of "security through obscurity" hiding a little bit more from your users will keep the curious ones a little more in check =).

When working with / we need to grab some potentially massive XML strings from the MgMap object and pass these along to the server side for processing.  Take the selection XML from the MgMap object, even a single entity selection can use a significant portion of the characters available in the query string.  On top of that, passing this data via query string requires that the data be URL encoded, using even more of our precious query string characters.

Depending on the design of your application it may not always be feasible to define a hard coded form, or even a form defined server side using ASP.NET.  In some cases (you guessed it - my case) you may want to use javascript and do all the work on the client side to define a form and pass the data long that way.

Well you're in luck, I found a pretty nice solution (WELL, at least I'm liking it  =]).   I'm kicking myself for not realizing this long ago, but oh well.  So the following javascript function demonstrates how to build, add, populate, and submit a form on the fly using some information from the MgMap object.

   1: function postData()   
   2: {   3: //get the map   
   3: mapObj = GetMap();   
   4:  
   5: //define the new form   
   6: var newForm = document.createElement("form");   
   7: //set the method to POST - the opposite of query strings..   
   8: newForm.method="POST";  
   9:  //add the new form to the current document  
  10:  document.body.appendChild(newForm);  
  11:  
  12:  //lets get some data and add it to the form  
  13:  AddFormElement(newForm, "MapName", oMap.GetMapName());  
  14:  AddFormElement(newForm, "SID", oMap.GetSessionId());  
  15:  //be sure you escape the selection XML - or you will get an error on post about a   
  16:  //"potentially dangerous form value".  Remember on the server side to Server.UrlDecode() it  
  17:  AddFormElement(newForm, "sel", escape(oMap.GetSelectionXML()));  
  18:  
  19:  //lets create our new window  
  20:  var szTarget = "targetWin"  
  21:  newForm.target = szTarget;  
  22:  //set the name/path of the ASPX file you want to process your form with  
  23:  newForm.action = "/url_to_open/file.aspx"  
  24:  
  25:  //open a new window to submit the form to.  Its a good idea to have a blank.htm so you don't get a file not found error  
  26:  var oWin = window.open("blank.htm",szTarget,'menubar=yes, resizable=yes,scrollbars=yes, status=no,toolbar=no,width=300, height=300');  
  27:  
  28:  //give the window focus.  Users like this  
  29:  oWin.focus();  
  30:  
  31:  //submit the form - it will now open in the new window  
  32:  newForm.submit();  
  33:  //remove the form from the document, we're done with it  
  34:  document.body.removeChild(newForm);  
  35:  }  
  36:  
  37:  function AddFormElement(form, elementName, elementVal)  
  38:  {  
  39:      var newElement = document.createElement("<input name='" + elementName + "' type='hidden'/>");  
  40:      newElement.value = elementVal;  
  41:      form.appendChild(newElement);  
  42:      return form;  
  43:  }

 

On the server side, you can now access this data from ASP.NET using Request.Form, for example Request.Form("MapName") would give you the map name.  Don't forget when retrieving the selection XML to run that through Server.UrlDecode, or HttpUtility.UrlDecode.

As usual, any comments, bugs, or rotten fruit - send em my way.  Enjoy!

  Technorati Profile
Wednesday, July 30, 2008 3:22:27 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |   |  Trackback
# Thursday, May 15, 2008

Google has recently released a new project called .  Their plan is to create the "Everything Else"DN, a more cross-platform web development encyclopedia per se.   As stated in the introduction video, MSDN is great for developing for the Microsoft-centric platforms - but really falls short with cross platform information.  Their goal is to get the web development community updating and adding to this resource over time.

This is of particular interest to me.  Now that I can no longer hide behind 'Mapguide 6.x needs an ActiveX, so IE is my only supported browser'. =)

In addition to a bunch of great , and reference documents - they're also releasing a good chunk of the javascript used by the Google applications - in an un-obfuscated state and with comments.  The entire library can be from the SVN repository and stored locally for faster, or offline access.

Technorati Tags: ,,,,,
CSS | DocType | DOM | Google | HTML | Javascript
Thursday, May 15, 2008 12:38:06 PM (Mountain Standard Time, UTC-07:00)  #    Disclaimer  |   |  Trackback