Web Info & Tutorials

September 13th, 2007

SVG ON IE VIA SILVERLIGHT VIA XSLT

Sam Ruby has done it again, this time taking Toine de Greef's work and making it better. Now your SVG can work on IE via Silverlight:

Cool. SVG to Silverlight via XSLT. But, embedding in HTML using comments? I think I can improve upon that.

Demo: Toucan. Rendered using native SVG on recent Gecko, Opera, and Webkit based browsers. Converted to Silverlight and rendered (after a brief delay) using client side XSLT on MSIE browsers with Silverlight.

This technique may also be useful for people who want to embed Silverlight into Webpages, which apparently isn’t so easy to do.

Demo: Raven — currently MSIE/Silverlight only, but clearly the reverse is also possible.

The magic bridge to the XML is in svg2xml.js:

JAVASCRIPT:
  1.  
  2. if (window.attachEvent) window.attachEvent("onload", function() {
  3.   xmls = document.getElementsByTagName('xml');
  4.   for (i=0; xmls.length>i; i++) {
  5.     var source = xmls[i].XMLDocument.documentElement;
  6.  
  7.     var script = document.createElement('script');
  8.     script.id = "_svg2xaml_" + i;
  9.     script.type = "text/xaml";
  10.     if (source.nodeName == 'Canvas') {
  11.       script.text = source.xml;
  12.     } else if (source.nodeName == 'svg') {
  13.       var svg = new ActiveXObject("Microsoft.XMLDOM");
  14.       svg.async = false;
  15.       svg.loadXML(source.xml);
  16.       var xsl = new ActiveXObject("Microsoft.XMLDOM");
  17.       xsl.async = false;
  18.       xsl.load("svg2xaml.xsl");
  19.       script.text = svg.transformNode(xsl);
  20.     } else {
  21.       continue; // ok, script is never used.  So what?  Shoot me?
  22.     }
  23.     xmls[i].parentElement.insertBefore(script,xmls[i]);
  24.  
  25.     var embed = document.createElement('object');
  26.     try {
  27.       embed.type = "application/x-silverlight";
  28.       embed.setAttribute('source', '#' + script.id);
  29.     } catch(err) {
  30.       embed.title="SVG or Silverlight required";
  31.     }
  32.     embed.width = xmls[i].style.width;
  33.     embed.height = xmls[i].style.height;
  34.     xmls[i].parentElement.insertBefore(embed,xmls[i]);
  35.   }
  36. });
  37.  

Toucan

September 13th, 2007

KAAZING: ENTERPRISE COMET FOR REAL TIME WEB 2.0

Kaazing is a new startup in the bay area that just announced itself to the world via a press release Kaazing and Terracotta Partner to Deliver Advanced Real-Time Web 2.0 Technology:

Kaazing Corporation and Terracotta, Inc. today announced a strategic alliance to deliver the software industry's most scalable and advanced real-time Web 2.0 technology for financial systems, online gaming, online sports and news broadcasting applications. The seamless integration between Kaazing's real-time Rich Internet Application (RIA) solution, Enterprise Comet, and Terracotta's Network Attached Memory software enables Kaazing customers to create and deploy scalable mission-critical real-time Web 2.0 solutions, such as trading system clients, online betting applications, performance monitoring, RFID/GPS tracking systems, and sports and news broadcasting applications.

Jonas Jacobi of Kaazing was at a conference that I am at in Oslo, so I cornered him to find out what this is all about. The video discusses how Kaazing has a GWT-like ability to take Java bytecode and produces Comet-enabled JavaScript that runs cross browser. Jonas demonstrated a JMS application, entirely written in Java, that runs in the browser itself. They will be showing off an online gaming application in short order.


September 13th, 2007

REPLACEHTML FOR WHEN INNERHTML DOGS YOU DOWN

Steven Levithan, of RegexPal, ran into some performance issues with innerHTML due to the fact that "every keydown event potentially triggers the destruction and creation of thousands of elements" so he started to look into it.

He has a test page that demonstrates the issue. Here is some sample input:

1000 elements...
innerHTML (destroy only): 156ms
innerHTML (create only): 15ms
innerHTML (destroy & create): 172ms
replaceHtml (destroy only): 0ms (faster)
replaceHtml (create only): 15ms (~ same speed)
replaceHtml (destroy & create): 15ms (11.5x faster)

15000 elements...
innerHTML (destroy only): 14703ms
innerHTML (create only): 250ms
innerHTML (destroy & create): 14922ms
replaceHtml (destroy only): 31ms (474.3x faster)
replaceHtml (create only): 250ms (~ same speed)
replaceHtml (destroy & create): 297ms (50.2x faster)

The code for his replaceHTML is:

JAVASCRIPT:
  1.  
  2. /* This is much faster than using (el.innerHTML = str) when there are many
  3. existing descendants, because in some browsers, innerHTML spends much longer
  4. removing existing elements than it does creating new ones. */
  5. function replaceHtml(el, html) {
  6.         var oldEl = (typeof el === "string" ? document.getElementById(el) : el);
  7.         var newEl = document.createElement(oldEl.nodeName);
  8.         // Preserve the element's id and class (other properties are lost)
  9.         newEl.id = oldEl.id;
  10.         newEl.className = oldEl.className;
  11.         // Replace the old with the new
  12.         newEl.innerHTML = html;
  13.         oldEl.parentNode.replaceChild(newEl, oldEl);
  14.         /* Since we just removed the old element from the DOM, return a reference
  15.         to the new element, which can be used to restore variable references. */
  16.         return newEl;
  17. };
  18.  
September 13th, 2007

PREMATURE AJAX-ULATIONS: AJAX SECURITY… IT’S STILL THE WEB

Bryan designer and Billy histrion gave a speech entitled Premature Ajax-ulations that came discover of their impact hunting at Ajax applications, and sight if they are secure.

They came to the ordinary closing that Ajax is not inherently insecure, but ignoring section makes it so:

“The player move opencast from Ajax is not from anything in the structure but because you’re adding functionality,” designer said. As your pussyfoot glides smoothly over a Google Map, the covering behindhand it is hornlike at work, constantly sending messages backwards and forward from the computer to the client.

“Ajax is rattling cool. You meet hit to clear an player toll for the player functionality,” designer said. That “extra price” includes mass base covering section prizewinning practices and cultivating act among development, QA and investigating teams. Many of those section practices should already be familiar.

White Hat Security also over that Ajax doesn’t drive a large move surface.

Of course, book Grossman of White Hat Security, also afraid the developers discover of their minds when he showed different tricks at The Ajax Experience in San Francisco, recently.