SlideShare a Scribd company logo
Client-side Transformations



                    @johnboxall
                         @vanjs
                    march 9 2011
What are client-side transformations?
What are client-side transformations?
      Transforming a webpage.
         On the client side.
Taking your content...

  <html>
      <body>
        <h1>one</h1>
        <h2>two</h2>
      <body>
  </html>
Taking your content... and remixing it!

  <html>                    <html>
      <body>                <body>
        <h1>one</h1>            <h2>two</h2>
        <h2>two</h2>            <h1>one</h1>
      <body>                <body>
  </html>                   </html>
Why would you ever want to do this?
Why would you ever want to do this?

Because you make mobile websites!
To make mobile websites we used to do this




 PHONE              PROXY           CONTENT
To make mobile websites we used to do this
• good                  • bad
• layout control        • politics
• resource control      • operations



  PHONE              PROXY             CONTENT
Client-side transformations let us do this



                       JS




  PHONE              PROXY             CONTENT
Client-side transformations let us do this
Client-side transformations let us do this
• good                      • bad
• layout control            • ???
• resource control

                       JS




  PHONE                                CONTENT
How should we implement layout control?


  <html>                 <html>
     <body>              <body>
       <h1>one</h1>         <h2>two</h2>
       <h2>two</h2>         <h1>one</h1>
     <body>              <body>
  </html>                </html>
How should we implement layout control?


  <html>

    <body>

     <h1>One</h1>

     <h2>Two</h1>

      <script type="text/javascript">
             $('h2').before('h1');
      </script>
    </body>

  </html>
How should we implement layout control?
  <html>
    <body>
      <script type="text/javascript">
        var $body = $('body').hide();
      </script>
     <h1>One</h1>
     <h2>Two</h1>
      <script type="text/javascript">
        $(function() {
             $('h2').before($('h1'));
             $body.show();
        });
      </script>

    </body>
  </html>
How can we implement resource control?

  <html>

  <body>

  <script type="text/javascript" src="one.js"></script>

  <script type="text/javascript" src="two.js"></script>




  </body>

  </html>
How can we implement resource control?

  <html>

  <body>

  <script type="text/javascript" src="one.js"></script>

  <script type="text/javascript" src="two.js"></script>

  <script type="text/javascript">

   $('[src="one.js"]').before($('[src="two.js"]'));

  </script>

  </body>

  </html>
How can we implement resource control?



<script type="text/javascript">
  var $doc = $(document).bind('beforeload', function(e) {
      e.preventDefault();
    });
</script>
How can we implement resource control?
  <html>
  <body>
  <script type="text/javascript">
   var scripts = [];
   var $doc = $(document).bind('beforeload', function(e) {
         scripts.push(e.target);
         e.preventDefault();
     });

   $(function() {
     $doc.unbind('beforeload');
     (function loadScripts() {
         var script = scripts.pop();
         if (script) $.getScript(script.src, loadScripts);
     })();
   });
  </script>
  <script type="text/javascript" src="one.js"></script>
  <script type="text/javascript" src="two.js"></script>
  </body>
  </html>
How can we implement resource control?
  <html>
  <body>
  <script type="text/javascript">
   var scripts = [];
   var $doc = $(document).bind('beforeload', function(e) {
         scripts.push(e.target);
         e.preventDefault();
     });

   $(function() {
     $doc.unbind('beforeload');
     (function loadScript() {
         var script = scripts.pop();
         if (script) $.getScript(script.src, loadScript);
     })();
   });
  </script>
  <script type="text/javascript" src="one.js"></script>
  <script type="text/javascript" src="two.js"></script>
  </body>
  </html>
How can we implement resource control?
  <html>
  <body>
  <script type="text/javascript">
   var scripts = [];
   var $doc = $(document).bind('beforeload', function(e) {
         scripts.push(e.target);
         e.preventDefault();
     });

   $(function() {
     $doc.unbind('beforeload');
     (function loadScript() {
         var script = scripts.pop();
         if (script) $.getScript(script.src, loadScript);
     })();
   });
  </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
  </body>
  </html>
How can we implement resource control?



 <script type="text/x-javascript">alert('one');</script>
How can we implement resource control?
<html>
<body>
 <noscript>



  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </noscript>
</body>
</html>
How can we implement resource control?
<html>
<body>
 <script type="text/javascript">
   document.write('x3Cnoscript>');
 </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </noscript>
</body>
</html>
How can we implement resource control?
<html>
<body>
 <script type="text/javascript">
   document.write('x3Cnoscript>');
 </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </noscript>
</body>
</html>
How can we implement resource control?
<html>
<body>
 <script type="text/javascript">
   document.write('x3Cnoscript>');
 </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </noscript>
</body>
</html>
How can we implement resource control?
<html>
<body>
 <script type="text/javascript">
   document.write('x3Cstyle type="text/x-css">');
 </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </style>
</body>
</html>
How can we implement resource control?
<html>
<body>
 <script type="text/javascript">
   document.write('x3Cstyle type="text/x-css">');
 </script>
  <script type="text/javascript">alert('one');</script>
  <script type="text/javascript">alert('two');</script>
 </style>
 <script type="text/javascript">
   var $scripts = $($('style').html());
   $scripts.reverse();
   $('body').append($scripts);
 </script>
</body>
</html>
X Layout control

X Resource control
Let’s build a mobile site using CST.
var $content = $($('style').html());


var context = {
      '#title': $('h1', $content),
        '#price': $(div.price, $content).html(),
        '#sizes': (function() {
          return $('#size', $content);
        })
    }


var templateStr = [
        '<div id="title"></div>',
        '<div id="price"></div>',
        '<div id="sizes"></div>'
    ].join('');


var $transform = $.template(templateStr, context);


$('body').append($transform);
var $content = $($('style').html());


var context = {
      '#title': $('h1', $content),
        '#price': $(div.price, $content).html(),
        '#sizes': (function() {
          return $('#size', $content);
        })
    }


var templateStr = [
        '<div id="title"></div>',
        '<div id="price"></div>',
        '<div id="sizes"></div>'
    ].join('');


var $transform = $.template(templateStr, context);


$('body').append($transform);
var $content = $($('style').html());


var context = {
      '#title': $('h1', $content),
        '#price': $(div.price, $content).html(),
        '#sizes': (function() {
          return $('#size', $content);
        })
    }


var templateStr = [
        '<div id="title"></div>',
        '<div id="price"></div>',
        '<div id="sizes"></div>'
    ].join('');


var $transform = $.template(templateStr, context);


$('body').append($transform);
var $content = $($('style').html());


var context = {
      '#title': $('h1', $content),
        '#price': $(div.price, $content).html(),
        '#sizes': (function() {
          return $('#size', $content);
        })
    }


var templateStr = [
        '<div id="title"></div>',
        '<div id="price"></div>',
        '<div id="sizes"></div>'
    ].join('');


var $transform = $.template(templateStr, context);


$('body').append($transform);
Client-side Transformations
       PS. We’re hiring:

    http://mobify.me/jobs/
                           @johnboxall
                                @vanjs
                           march 9 2011

More Related Content

PDF
Short intro to JQuery and Modernizr
PPTX
PDF
jQuery and Rails, Sitting in a Tree
PPTX
jQuery, CSS3 and ColdFusion
KEY
Google
KEY
Authentication
PDF
Jquery presentation
PDF
Introducing jQuery
Short intro to JQuery and Modernizr
jQuery and Rails, Sitting in a Tree
jQuery, CSS3 and ColdFusion
Google
Authentication
Jquery presentation
Introducing jQuery

What's hot (20)

PDF
Opencast Admin UI - Introduction to developing using AngularJS
PPTX
PPTX
JavaScript and jQuery Basics
KEY
Html5 For Jjugccc2009fall
DOC
Jquery examples
PPTX
Dart and AngularDart
PPTX
Client Web
PDF
jQuery Essentials
PPTX
`From Prototype to Drupal` by Andrew Ivasiv
PPTX
jQuery Best Practice
PPTX
Dynamic documentation - SRECON 2017
PDF
GDI Seattle - Intro to JavaScript Class 4
PPTX
jQuery PPT
PDF
Get AngularJS Started!
PDF
jQuery Presentation to Rails Developers
PDF
Solr and symfony in Harmony with SolrJs
PPTX
Java script
PDF
Prototype & jQuery
PDF
Merb jQuery
Opencast Admin UI - Introduction to developing using AngularJS
JavaScript and jQuery Basics
Html5 For Jjugccc2009fall
Jquery examples
Dart and AngularDart
Client Web
jQuery Essentials
`From Prototype to Drupal` by Andrew Ivasiv
jQuery Best Practice
Dynamic documentation - SRECON 2017
GDI Seattle - Intro to JavaScript Class 4
jQuery PPT
Get AngularJS Started!
jQuery Presentation to Rails Developers
Solr and symfony in Harmony with SolrJs
Java script
Prototype & jQuery
Merb jQuery
Ad

Viewers also liked (20)

ODP
τα Olpc xo
DOCX
PPT
App Day - Show Your App Award - LOCA
PPTX
Os 10 mandamentos
PPTX
Vinde, adoremos!
PPT
Health and Personal Care
PPS
Saber Amar
PDF
BiblioAnimação julho
PPS
PPS
Ilusãodeótica
PPT
Staffing officer kpi
PPT
La bimba
PPT
Mateus 028
PPTX
Salud
PDF
BOLETIM GRALHA AZUL NO. 47 - SOBRAMES - PR - JUNHO 2014
DOCX
Sap modules standard
PPTX
PDF
Apresentação aldeia
τα Olpc xo
App Day - Show Your App Award - LOCA
Os 10 mandamentos
Vinde, adoremos!
Health and Personal Care
Saber Amar
BiblioAnimação julho
Ilusãodeótica
Staffing officer kpi
La bimba
Mateus 028
Salud
BOLETIM GRALHA AZUL NO. 47 - SOBRAMES - PR - JUNHO 2014
Sap modules standard
Apresentação aldeia
Ad

Similar to Client-side Transformations (20)

PDF
jQuery (MeshU)
PPT
J query b_dotnet_ug_meet_12_may_2012
PDF
jQuery Mobile: For Fun and Profit
PDF
HTML5 and the dawn of rich mobile web applications pt 2
PDF
Delivering a Responsive UI
PDF
Attractive HTML5~開発者の視点から~
PDF
High Performance Front-End Development
PDF
jQuery (BostonPHP)
PDF
HyperLight Websites
PDF
handout-05b
PDF
handout-05b
PDF
Using jQuery to Extend CSS
PPT
Jquery presentation
PDF
Write Less Do More
PDF
Yearning jQuery
PDF
C3 웹기술로만드는모바일앱
PDF
bcgr3-jquery
PDF
bcgr3-jquery
PPTX
Html5 and web technology update
PDF
Please dont touch-3.5
jQuery (MeshU)
J query b_dotnet_ug_meet_12_may_2012
jQuery Mobile: For Fun and Profit
HTML5 and the dawn of rich mobile web applications pt 2
Delivering a Responsive UI
Attractive HTML5~開発者の視点から~
High Performance Front-End Development
jQuery (BostonPHP)
HyperLight Websites
handout-05b
handout-05b
Using jQuery to Extend CSS
Jquery presentation
Write Less Do More
Yearning jQuery
C3 웹기술로만드는모바일앱
bcgr3-jquery
bcgr3-jquery
Html5 and web technology update
Please dont touch-3.5

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Encapsulation theory and applications.pdf
PDF
KodekX | Application Modernization Development
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Building Integrated photovoltaic BIPV_UPV.pdf
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Unlocking AI with Model Context Protocol (MCP)
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Approach and Philosophy of On baking technology
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The Rise and Fall of 3GPP – Time for a Sabbatical?
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
Encapsulation theory and applications.pdf
KodekX | Application Modernization Development
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

Client-side Transformations

  • 1. Client-side Transformations @johnboxall @vanjs march 9 2011
  • 2. What are client-side transformations?
  • 3. What are client-side transformations? Transforming a webpage. On the client side.
  • 4. Taking your content... <html> <body> <h1>one</h1> <h2>two</h2> <body> </html>
  • 5. Taking your content... and remixing it! <html> <html> <body> <body> <h1>one</h1> <h2>two</h2> <h2>two</h2> <h1>one</h1> <body> <body> </html> </html>
  • 6. Why would you ever want to do this?
  • 7. Why would you ever want to do this? Because you make mobile websites!
  • 8. To make mobile websites we used to do this PHONE PROXY CONTENT
  • 9. To make mobile websites we used to do this • good • bad • layout control • politics • resource control • operations PHONE PROXY CONTENT
  • 10. Client-side transformations let us do this JS PHONE PROXY CONTENT
  • 12. Client-side transformations let us do this • good • bad • layout control • ??? • resource control JS PHONE CONTENT
  • 13. How should we implement layout control? <html> <html> <body> <body> <h1>one</h1> <h2>two</h2> <h2>two</h2> <h1>one</h1> <body> <body> </html> </html>
  • 14. How should we implement layout control? <html> <body> <h1>One</h1> <h2>Two</h1> <script type="text/javascript"> $('h2').before('h1'); </script> </body> </html>
  • 15. How should we implement layout control? <html> <body> <script type="text/javascript"> var $body = $('body').hide(); </script> <h1>One</h1> <h2>Two</h1> <script type="text/javascript"> $(function() { $('h2').before($('h1')); $body.show(); }); </script> </body> </html>
  • 16. How can we implement resource control? <html> <body> <script type="text/javascript" src="one.js"></script> <script type="text/javascript" src="two.js"></script> </body> </html>
  • 17. How can we implement resource control? <html> <body> <script type="text/javascript" src="one.js"></script> <script type="text/javascript" src="two.js"></script> <script type="text/javascript"> $('[src="one.js"]').before($('[src="two.js"]')); </script> </body> </html>
  • 18. How can we implement resource control? <script type="text/javascript"> var $doc = $(document).bind('beforeload', function(e) { e.preventDefault(); }); </script>
  • 19. How can we implement resource control? <html> <body> <script type="text/javascript"> var scripts = []; var $doc = $(document).bind('beforeload', function(e) { scripts.push(e.target); e.preventDefault(); }); $(function() { $doc.unbind('beforeload'); (function loadScripts() { var script = scripts.pop(); if (script) $.getScript(script.src, loadScripts); })(); }); </script> <script type="text/javascript" src="one.js"></script> <script type="text/javascript" src="two.js"></script> </body> </html>
  • 20. How can we implement resource control? <html> <body> <script type="text/javascript"> var scripts = []; var $doc = $(document).bind('beforeload', function(e) { scripts.push(e.target); e.preventDefault(); }); $(function() { $doc.unbind('beforeload'); (function loadScript() { var script = scripts.pop(); if (script) $.getScript(script.src, loadScript); })(); }); </script> <script type="text/javascript" src="one.js"></script> <script type="text/javascript" src="two.js"></script> </body> </html>
  • 21. How can we implement resource control? <html> <body> <script type="text/javascript"> var scripts = []; var $doc = $(document).bind('beforeload', function(e) { scripts.push(e.target); e.preventDefault(); }); $(function() { $doc.unbind('beforeload'); (function loadScript() { var script = scripts.pop(); if (script) $.getScript(script.src, loadScript); })(); }); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </body> </html>
  • 22. How can we implement resource control? <script type="text/x-javascript">alert('one');</script>
  • 23. How can we implement resource control? <html> <body> <noscript> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </noscript> </body> </html>
  • 24. How can we implement resource control? <html> <body> <script type="text/javascript"> document.write('x3Cnoscript>'); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </noscript> </body> </html>
  • 25. How can we implement resource control? <html> <body> <script type="text/javascript"> document.write('x3Cnoscript>'); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </noscript> </body> </html>
  • 26. How can we implement resource control? <html> <body> <script type="text/javascript"> document.write('x3Cnoscript>'); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </noscript> </body> </html>
  • 27. How can we implement resource control? <html> <body> <script type="text/javascript"> document.write('x3Cstyle type="text/x-css">'); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </style> </body> </html>
  • 28. How can we implement resource control? <html> <body> <script type="text/javascript"> document.write('x3Cstyle type="text/x-css">'); </script> <script type="text/javascript">alert('one');</script> <script type="text/javascript">alert('two');</script> </style> <script type="text/javascript"> var $scripts = $($('style').html()); $scripts.reverse(); $('body').append($scripts); </script> </body> </html>
  • 29. X Layout control X Resource control
  • 30. Let’s build a mobile site using CST.
  • 31. var $content = $($('style').html()); var context = { '#title': $('h1', $content), '#price': $(div.price, $content).html(), '#sizes': (function() { return $('#size', $content); }) } var templateStr = [ '<div id="title"></div>', '<div id="price"></div>', '<div id="sizes"></div>' ].join(''); var $transform = $.template(templateStr, context); $('body').append($transform);
  • 32. var $content = $($('style').html()); var context = { '#title': $('h1', $content), '#price': $(div.price, $content).html(), '#sizes': (function() { return $('#size', $content); }) } var templateStr = [ '<div id="title"></div>', '<div id="price"></div>', '<div id="sizes"></div>' ].join(''); var $transform = $.template(templateStr, context); $('body').append($transform);
  • 33. var $content = $($('style').html()); var context = { '#title': $('h1', $content), '#price': $(div.price, $content).html(), '#sizes': (function() { return $('#size', $content); }) } var templateStr = [ '<div id="title"></div>', '<div id="price"></div>', '<div id="sizes"></div>' ].join(''); var $transform = $.template(templateStr, context); $('body').append($transform);
  • 34. var $content = $($('style').html()); var context = { '#title': $('h1', $content), '#price': $(div.price, $content).html(), '#sizes': (function() { return $('#size', $content); }) } var templateStr = [ '<div id="title"></div>', '<div id="price"></div>', '<div id="sizes"></div>' ].join(''); var $transform = $.template(templateStr, context); $('body').append($transform);
  • 35. Client-side Transformations PS. We’re hiring: http://mobify.me/jobs/ @johnboxall @vanjs march 9 2011

Editor's Notes

  • #2: \n
  • #3: The ability to transform the way a webpage is loaded by the client.\n
  • #4: The ability to transform the way a webpage is loaded by the client.\n
  • #5: SHOW ME\n
  • #6: Totally remix the page.\nUse existing components - or don&amp;#x2019;t\nHoney Badger - it just care. We don&amp;#x2019;t care about your original HTML. (but we could if we wanted to)\n
  • #7: \n
  • #8: \n
  • #9: \n
  • #10: \n
  • #11: \n
  • #12: Why didn&amp;#x2019;t you just do this in the beginning\n
  • #13: \n
  • #14: So we got this, how are we actually gonna make it work?\n
  • #15: So we got this, how are we actually gonna make it work?\n
  • #16: So we got this, how are we actually gonna make it work?\n
  • #17: So we got this, how are we actually gonna make it work?\n
  • #18: So we got this, how are we actually gonna make it work?\n
  • #19: http://developer.apple.com/library/safari/#documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW9\n
  • #20: \n
  • #21: \n
  • #22: \n
  • #23: \n
  • #24: So ... can we do that dynamcially?\n
  • #25: So ... can we do that dynamcially?\n
  • #26: So ... can we do that dynamcially?\n
  • #27: So ... can we do that dynamcially?\n
  • #28: So ... can we do that dynamcially?\n
  • #29: \n
  • #30: \n
  • #31: \n
  • #32: \n
  • #33: \n
  • #34: \n
  • #35: \n
  • #36: \n