Ajax to the Moon

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Notes on slide 1

    Remove technical session reference…are we sure we have to use the J1 template?

    Favorites, Groups & Events

    Ajax to the Moon - Presentation Transcript

    1. Ajax to the Moon Dave Johnson CTO and Co-founder Nitobi www.nitobi.com
    2. Agenda
      • Who I Am
      • Offline Ajax
      • Pushing Ajax
      • Ajax Performance
      • Summary
    3. Who I Am
      • Nitobi Enterprise Ajax Podcast
      • Enterprise Ajax book (Prentice Hall)
      • blogs.nitobi.com/dave
    4. What Do I Do?
      • Nitobi co-founder
      • Located in Vancouver, Canada
      • Ajax user-interface components for the enterprise
    5.  
    6. Clients
    7. Agenda
      • Who I Am
      • Offline Ajax
      • Pushing Ajax
      • Ajax Performance
      • Summary
    8. Offline Ajax http://www.flickr.com/photos/natearcher/378519540/
    9. Know your users
    10. Why Offline
      • Hard at work
      • Get on a plane
      • Keep on working
    11. http://www.flickr.com/photos/plakboek/339017053/
    12. Why Offline
      • Hard at work
      • Get on a plane
      • Keep on working
      • Get Internet connection and sync data
      • More common than you may think!
    13.  
    14.  
    15. But Seriously
      • Internet connections do not grow on trees
      • Try going to Sun HQ and getting on their network!
    16. How Does it Work?
      • Work offline
      • Store data locally when browser is closed
      • Send data back to server when connected
    17.  
    18. Storage
      • Cookies
      • Firefox / Internet Explorer only
      • Flash
      • Install software
    19. Cookies
      • 4Kb of storage per domain
      • Easily deleted – probably suspected as Spyware
    20. Firefox 2.0 Offline Storage
      • Cookies on steroids
      • Data not available across sessions
      • 5Mb of storage by default
      • A bit buggy at the moment but Firefox 3 should have global storage across sessions
      • <html>
      • <head>
      • <script type=”text/javascript”>
      • function saveSession(myparam,myvalue) {
      • // will save the attribute myparam with value myvalue
      • sessionStorage[myparam] = myvalue;
      • }
      • function loadSession(myparam) {
      • // will retrieve myparam from sessionStorage
      • var myresult = sessionStorage[myparam];
      • return myresult;
      • }
      • </script>
      • </head>
      • <body>
      • <form id=&quot;myform&quot; name=&quot;myform&quot;>
      • <input type=&quot;text&quot; id=&quot;myvalue&quot; name=&quot;myvalue&quot;>
      • <input type=&quot;button&quot; value=&quot;Save&quot;
      • onclick=&quot;saveSession('myattribute',myform.myvalue.value)&quot;>
      • <input type=&quot;button&quot; value=&quot;Load&quot;
      • onclick=&quot;alert(loadSession('myattribute'))&quot;>
      • </form>
      • </body>
      • </html>
    21. Internet Explorer userData Behavior
      • Access data across sessions
      • 128Kb limit for Internet (512Kb for Intranet)
      • Relies on Internet Explorer Behaviors
      • What about HTML Applications?
      • <html>
      • <head>
      • <script type=”text/javascript”>
      • function save(myparam,myvalue) {
      • $(“storageInput”).setAttribute(myparam, myvalue).save(&quot;mydata&quot;);
      • }
      • function load(myparam) {
      • return $(“storageInput”).load(&quot;mydata&quot;).getAttribute(myparam);
      • }
      • </script>
      • <style>
      • .storage {
      • behavior:url(#default#userData);
      • display:none;
      • }
      • </style>
      • </head>
      • <body>
      • <form id=&quot;myform&quot; name=&quot;myform&quot;>
      • <input type=&quot;text&quot; id=&quot;myvalue&quot; name=&quot;myvalue&quot;>
      • <input type=&quot;button&quot; value=&quot;Save&quot; onclick=&quot;save('myattr',myform.myvalue.value)&quot;>
      • <input type=&quot;button&quot; value=&quot;Load&quot; onclick=&quot;alert(load('myattribute'))&quot;>
      • <div id=”storageInput” class=”storage”></div>
      • </form>
      • </body>
      • </html>
    22. Flash SharedObject Storage
      • Access data across sessions
      • User definable storage limit (default of 100Kb)
      • Back to Flash 6 (98% adoption)
    23. Flash Movie
      • import flash.external.ExternalInterface;
      • function saveAttribute(datastore, paramname, paramvalue) {
      • mySharedObject = SharedObject.getLocal(datastore);
      • mySharedObject.data[paramname] = paramvalue;
      • mySharedObject.flush();
      • }
      • function loadAttribute(datastore,paramname) {
      • return SharedObject.getLocal(datastore).data[paramname];
      • }
      • ExternalInterface.addCallback(&quot; saveAttribute &quot;, this, saveAttribute);
      • ExternalInterface.addCallback(&quot; loadAttribute &quot;, this, loadAttribute);
      • <html>
      • <head>
      • <script>
      • function thisMovie(movieName) {
      • if (navigator.appName.indexOf(&quot;Microsoft&quot;) != -1)
      • return window[movieName];
      • else
      • return document[movieName];
      • }
      • function saveData(store, param, pvalue) {
      • thisMovie(‘myStorage’).saveAttribute(store,param,pvalue);
      • }
      • function loadData(store, param) {
      • return(thisMovie(‘myStorage’).loadAttribute(store,param));
      • }
      • </script>
      • </head>
      • <body>
      • <object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000“
      • codebase=&quot;…&quot;
      • width=&quot;1&quot; height=&quot;1&quot; id=&quot;myStorage&quot; align=&quot;middle&quot;>
      • <param name=&quot;movie&quot; value=&quot;localstore.swf&quot; />
      • <param nam=&quot;allowScriptAccess&quot; value=&quot;always&quot;>
      • <embed src=&quot;localstore.swf&quot; allowScriptAccess=&quot;always&quot; width=&quot;1&quot; height=&quot;1&quot; name=&quot;myStorage“
      • type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; />
      • </object>
      • </body>
      • </html>
      • <html>
      • <head>
      • <script>
      • function thisMovie(movieName) {
      • if (navigator.appName.indexOf(&quot;Microsoft&quot;) != -1)
      • return window[movieName];
      • else
      • return document[movieName];
      • }
      • function saveData(store, param, pvalue) {
      • thisMovie(‘myStorage’).saveAttribute(store,param,pvalue);
      • }
      • function loadData(store, param) {
      • return(thisMovie(‘myStorage’).loadAttribute(store,param));
      • }
      • </script>
      • </head>
      • <body>
      • <object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000“
      • codebase=&quot;…&quot;
      • width=&quot;1&quot; height=&quot;1&quot; id=&quot;myStorage&quot; align=&quot;middle&quot;>
      • <param name=&quot;movie&quot; value=&quot;localstore.swf&quot; />
      • <param nam=&quot;allowScriptAccess&quot; value=&quot;always&quot;>
      • <embed src=&quot;localstore.swf&quot; allowScriptAccess=&quot;always&quot; width=&quot;1&quot; height=&quot;1&quot; name=&quot;myStorage“
      • type=&quot;application/x-shockwave-flash&quot; pluginspage=&quot;http://www.macromedia.com/go/getflashplayer&quot; />
      • </object>
      • </body>
      • </html>
    24. Apollo
      • Adobe’s new runtime – currently Alpha
      • Offline capable, runs from your computer
      • A lot more than just offline!
        • Flex + WebKit (i.e. Safari) in one
    25. Web Proxy
      • Proxy auto-config – browser proxy settings
      • JavaScript file with FindProxyForURL
      • Forward requests to a local proxy for interested domains
      • Used by the Dojo Toolkit
    26. Salesforce.com Local Proxy
    27. Whole Hog
      • Web server
      • Database
      • Run locally
      • Zimbra uses this approach
    28. Issues
      • Performance
      • Concurrency
        • Your own data or shared?
      • End user requirements
        • Are they a captive user?
      • Penetration
    29. Proxy Whole Hog Flash Browser Specific Cookies Concurrency Performance End user reqs / Penetration
    30. Proxy Whole Hog Flash Browser Specific Cookies Concurrency Performance End user reqs / Penetration
    31. Proxy Whole Hog Flash Browser Specific Cookies Concurrency Performance End user reqs / Penetration
    32. Proxy Whole Hog Flash Browser Specific Cookies Concurrency Performance End user reqs / Penetration
    33. Proxy Whole Hog Flash Browser Specific Cookies Concurrency Performance End user reqs / Penetration
    34. Agenda
      • Who I Am
      • Offline Ajax
      • Pushing Ajax
      • Ajax Performance
      • Summary
    35. Pushing Ajax http://www.flickr.com/photos/vidiot/69075298/
    36. Watch out for your thumb
    37. Why Push?
      • Keep client up to date
      • Collaboration
        • Documents
        • Communication
      • Time sensitive data
    38. How Does it Work? Big scary Internet Innocent MySpace user MySpace Evil Empire TM
    39. Polling
      • Means to the same end
      • Easy to build
      • Request update from server every N seconds
      • Support thousands of concurrent users?
      • users / pollTime = requests per second
    40. http://www.flickr.com/photos/roadhunter/68017710/
    41. How Does it Work? Big scary Internet Innocent MySpace user MySpace Evil Empire TM thumb twiddling …
    42. Push
      • Keep connection to server open
      • Server writes to stream when ready
      • Support thousands of concurrent users?
      • numConnections ≡ numServerThreads
    43. http://www.flickr.com/photos/rev_bri/112249215/
    44. Asynchronous Servlets
      • Sun – Grizzly HTTP Connector
      • BEA – AbstractAsyncServlet
      • Tomcat 6.x – CometServlet
      • Jetty – Continuations
      • No standards here
    45. Cometd / Bayeux
      • Cometd reference implementation
      • Bayeux pub/sub on top of Comet
        • Think JMS for JavaScript
    46. DEMO
      • http://localhost:8080/examples/magnets/
    47. Piggyback
      • The middle of the road
      • Send data to client with any other responses
    48. Other Approaches to Push
      • LiveCycle Data Services
      • LightStreamer
    49. Issues
      • Server load
      • Internet Explorer
    50. Agenda
      • Who I Am
      • Offline Ajax
      • Pushing Ajax
      • Ajax Performance
      • Summary
    51. Ajax Performance http://www.flickr.com/photos/edfladung/451378444/ Ajax Performance
    52. Ask questions first, optimize second
    53. What is the Bottleneck?
      • Situation dependent
      • How much data?
      • What type of data?
      • How many server hits?
      • What are the common workflows?
      • What browsers are you targeting?
      • What is the existing infrastructure?
    54. Lifecycle
    55. Data Formats
      • XML
        • <xml>You know this</xml>
      • JSON
        • {“json”:[“maybe”,”you”,don’t”],”know”:”this”}
      • HTML
        • <html>Looks familiar</html>
      • Text
      • Images
    56. Server
      • HTML
        • Whatever you use today
      • XML
        • Standard support for object serialization
        • Similar to HTML
      • JSON
        • Easy to add on
    57. Bandwidth
      • HTML
        • <div style=“color: red;”>Napoleon</div>
      • XML
        • <customer><name>Napoleon</name></customer>
        • <c n=“Napoleon”/>
      • JSON
        • {“customer”:[{“Name”:”Napoleon”}]}
        • {“c”:[{“n”:”Napoleon”}]}
      • Polling, code size etc
    58. JavaScript
      • HTML
        • Nothing to do
      • XML
        • Transform with XSLT (browser dependent)
        • Iterate over XML DOM nodes and string build
        • Iterate over XML DOM nodes and create HTML DOM nodes
      • JSON
        • eval() the block of JSON to a JavaScript object
        • Transform with JSON Templates
        • Iterate through JavaScript arrays and string build
        • Iterate through JavaScript arrays and create HTML DOM nodes
    59. Internet Explorer
    60. Firefox
    61. http://www.jamesward.org/census/ Firefox Internet Explorer
    62. XSLT Cross Browser Performance
    63. Don’t Lose your Keys
      • <xsl:key name=“sales-by-customer” match=“customer” use=“@name” />
      • <xsl:value-of select=&quot;key(‘sales-by-customer', $CustomerName)&quot;>
    64. XSLT Performance
    65. JSON with Padding (JSONP)
      • Most apps use XHR
      • Using XHR for JSON necessitates eval()
      • eval() is slow
      • Instead dynamically insert a <script> tag and have the returned JavaScript call a function …
      • http://localhost/javaone/
    66. The Fast, Server Dependent Way
      • function getPostsSi() {
      • var elem = document.createElement(&quot;script&quot;);
      • elem.src = &quot;http://del.icio.us/feeds/json/davyjones? callback = buildHtml &quot;;
      • document.body.appendChild(elem);
      • }
      • function buildHtml (obj) {
      • var s = [];
      • for (var i=0; i<obj.length; i++) {
      • s.push(&quot;<div><a href='&quot;+obj[i].u+&quot;'>&quot; + obj[i].d + &quot;</a></div>&quot;);
      • }
      • $(&quot;container&quot;).innerHTML = s.join(&quot;&quot;);
      • }
    67. The Slow, Server Agnostic Way
      • function getPostsXhr() {
      • var xhr = new nitobi.ajax.HttpRequest();
      • xhr.handler = &quot;http://localhost/feeds/json/davyjones&quot;;
      • xhr.onComplete.subscribe(xhrDataReady);
      • xhr.send();
      • }
      • function xhrDataReady(evtArgs) {
      • var obj = eval(&quot;(&quot;+evtArgs+&quot;)&quot;);
      • buildHtml (obj);
      • }
    68. HTML DOM
      • HTML
        • $(“myNode”).innerHTML = “<div>Napoleon</div>”;
      • XML
        • innerHTML
        • DOM manipulations
          • createElement(“div”), appendChild(node), etc
      • JSON
        • innerHTML
        • DOM manipulations
      • Interactivity
    69. General DOM Function
    70. Most Wanted
      • innerHTML – consider HTML tags, floats, events
      • offsetTop / Left
      • getBoundingClientRect / getBoxObjectFor
      • Stylesheets
    71. Watch Out for Memory Leaks
      • Circular loops between the DOM and JavaScript
      • Use Drip to find them
      <script type=“text/javascript”> var domNode = $(“myDomNode”); domNode .foo = domNode ; </script> expando
    72. JavaScript Compression
      • Removing comments
      • Removing whitespace
      • Removing new-line characters
      • Replacing variables with shorter names
    73. Simple Example var _a = function (a){ var b=0; var c=a.length; for ( var d=0;d<c;d++){b+=a[d];} return b/c;} var calcAverage =_a; /** * @private */ var _calcAverage = function(aNumber) { var nTotal = 0; var iLength = aNumber.length; for ( var iIndex = 0; i<iLength; i++) { nTotal += aNumber[iIndex]; } return nTotal/iLength; } /** * Calculates the average of an array of numbers. * @param {Array} Array of numbers to average. */ var calcAverage = _calcAverage;
    74. Rhino Minification / Obfuscation
      • <target
      • name=&quot;obfuscateJS&quot;
      • description=&quot;compress and obfuscate code&quot;>
      • <java
      • classname=&quot;org.mozilla.javascript.tools.shell.Main“
      • dir=&quot;${basedir}uild hinoin&quot;
      • fork=&quot;true&quot;
      • output=&quot;${basedir}outputsrc_obfuscated.js&quot;>
      • <arg line=&quot;-c ${basedir}inputsrc.js &quot; />
      • <classpath>
      • <pathelement path=&quot;${basedir}uild hinoinjs.jar&quot; />
      • </classpath>
      • </java>
      • </target>
    75. Compression
      • Request
        • Accept-Encoding: gzip,deflate
      • Response
        • Content-Encoding: gzip || deflate
      • IIS and Apache dynamically GZip / Deflate content and cache it
      • All modern browsers support compressed content
        • Internet Explorer 6 SP1 had some problems
      • IE, Firefox, Opera accept compressed content _without_ Content-Encoding header
    76. Apache Compression
      • # Compress everything unless excluded below.
      • SetOutputFilter DEFLATE
      • SetInputFilter DEFLATE
      • SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
      • SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|rar)$ no-gzip dont-vary
      • SetEnvIfNoCase Request_URI .(?:pdf|avi|mov|mp3|rm)$ no-gzip dont-vary
      • # Explicity compress certain file types
      • AddOutputFilterByType DEFLATE text/html text/plain text/xml
    77. How Small is It? Size (Kb) Original 9.3 Minify 3.9 GZip / Deflate 2.8 Minify + GZip / Deflate 1.3 Size Reduction 86% Expected Results for JavaScript Compression
    78. Content Merging
      • Reduce download overhead by merging resources
        • JavaScript
        • Cascading Stylesheets
        • Images
      • Careful with caching though!
    79. Image Merging
    80. Image Merging
      • <html>
      • <head>
      • <style type=&quot;text/css&quot; media=&quot;screen&quot;>
      • .colour {clip: rect(0px 135px 125px 0px);}
      • .grayscale {
      • left:-135px;
      • clip: rect(0px 270px 125px 135px);
      • }
      • .grayscale, .colour {
      • position:absolute;
      • width: 270px;height: 125px;
      • background: url(images/nitobi.jpg);
      • }
      • .container {
      • height:125px;width:135px;
      • position:relative;
      • }
      • </style>
      • </head>
      • <body>
      • <div class=&quot;container&quot;><div class=&quot;colour&quot;></div></div>
      • <div class=&quot;container&quot;><div class=&quot;grayscale&quot;></div></div>
      • </body>
      • </html>
      clip: rect(0px 135px 125px 0px); clip: rect(0px 270px 125px 135px); background: url(images/nitobi.jpg);
    81. Agenda
      • Who I Am
      • Offline Ajax
      • Pushing Ajax
      • Ajax Performance
      • Summary
    82. Summary
      • “ Work Offline” – know your users
        • Browser specific, Flash or Install
        • Usability
      • Push – watch out for your thumb
        • Real-time collaboration
        • Usability
      • Performance – ask questions first, optimize later
        • Be careful but not too careful
        • Usability
    83. Q&A
      • Dave Johnson
      • www.nitobi.com
      • [email_address]
      • http://blogs.nitobi.com/dave

    + davejohnsondavejohnson, 3 years ago

    custom

    3551 views, 0 favs, 1 embeds more stats

    CommunityOne presentation about offline Ajax, Ajax more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3551
      • 3548 on SlideShare
      • 3 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 170
    Most viewed embeds
    • 3 views on http://blogs.nitobi.com

    more

    All embeds
    • 3 views on http://blogs.nitobi.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories