<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>JMPerez Blog</title> <atom:link href="http://blog.josemanuelperez.es/feed/" rel="self" type="application/rss+xml" /><link>http://blog.josemanuelperez.es</link> <description>Web development, standards, design patterns and some other good practices</description> <lastBuildDate>Fri, 27 Jan 2012 07:30:45 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>On webkit-only mobile javascript libraries</title><link>http://blog.josemanuelperez.es/2012/01/webkit-only-mobile-js-libraries/</link> <comments>http://blog.josemanuelperez.es/2012/01/webkit-only-mobile-js-libraries/#comments</comments> <pubDate>Sun, 08 Jan 2012 16:39:02 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[js library]]></category> <category><![CDATA[windows phone]]></category> <category><![CDATA[wp7]]></category> <category><![CDATA[zepto]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=526</guid> <description><![CDATA[Many mobile-focused JS libraries doesn't support Opera or Windows Phone 7. Thus, not all smartphones are covered.]]></description> <content:encoded><![CDATA[<p><a href="http://blog.josemanuelperez.es/wp-content/uploads/2012/01/jq-mobi-requires-webkit-browser.png"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2012/01/jq-mobi-requires-webkit-browser-164x300.png" alt="jQ.mobi demo running on a WP7 emulator" title="jq-mobi-requires-webkit-browser" class="alignright" /></a>During last days I have been looking for a Javascript library targeted to recent mobile devices. Though I am familiar with jQuery, there is a lot of code that deals with browsers and issues that are specific to desktop browsers, but not to mobile ones, at least when working with browsers running on smartphones and tablets.</p><p>All of them work seamlessly on webkit browsers, which are the most broadly used ones, but only a few take into account Internet Explorer, Opera Mobile or Firefox.</p><p><span id="more-526"></span></p><h2>The current status of modern mobile browsers</h2><p>Although there is a vast diversity of mobile devices, I will focus on those running on smartphones and tablets, which normally have a quite good support of HTML5 features and provide a native DOM selector through <code>document.querySelector</code> function.</p><p>There are nice sites showing comparison of different Javascript libraries for mobile, i.e <a href="http://www.markus-falk.com/mobile-frameworks-comparison-chart/">Markus Falk&#8217;s</a>.</p><p>In my case I would like to find a library that works across all devices that support HTML5. I have been using <a href="http://zeptojs.com">zepto.js</a> for some time. It is quite small and it has a jQuery-ish syntax. However, it lacks support of some HTML5 compliant browsers:</p><blockquote><p>Zepto supports Safari, Chrome, Firefox and Opera and any mobile WebKit-based browser, including iOS Mobile Safari, Android browser, HP webOS browser, Blackberry Tablet OS browser and others. Zepto does not support Internet Explorer.</p></blockquote><p>You are the only one who knows better what platforms your products are targeted to and what browsers your visitors are using to reach your site. Just keep in mind that there are more players apart from webkit.</p><h3>Windows Phone 7</h3><p>Not supporting Internet Explorer, Zepto doesn&#8217;t support Windows Phone 7 devices. <a href="http://en.wikipedia.org/wiki/Windows_Phone#Web_browser">WP7&#8242;s browser</a> is an Internet Explorer version for mobile, that at least in its latest version 9 supports widely HTML5 features. At least from a mobile-targeted JS library point of view, it provides <code>document.querySelectorAll</code> and it is compatible with the standard way to add, for instance, an event using <code>element.addEventListener</code>.</p><p>Microsoft is working hard in order to provide Windows Phone 7 devices with a top browser that mobile specific libraries seem to ignore.</p><h3>Firefox for Mobile (aka Fennec)</h3><p>By only supporting webkit devices, Mozilla&#8217;s <a href="http://www.mozilla.org/mobile/">Firefox for Mobile</a> is put aside, even though they are working hard on adding promising HTML5 APIs. Recently, I got the chance to play around with the Battery API, the Camera API and the Vibrator API checking out <a href="http://johnhammink.blogspot.com/2011/11/lets-have-look-at-some-recently-landed.html">John Hammink&#8217;s demos</a> using a nightly version of this browser on an Android phone.</p><h3>Opera Mobile</h3><p><a href="http://my.opera.com/operamobile/blog/opera-mobile-11-for-android-and-symbian">Opera Mobile</a>, being powered by a Presto engine, is also disregarded by webkit-only frameworks. And it seems they are doing a great job supporting HTML5 functionality. Seeing how they are performing in the <a href="https://market.android.com/details?id=com.opera.browser">Android Market</a> with increasing download rates and good reviews, we should keep an eye on it.</p><h2>A tip for mobile JS libraries developers</h2><p>It is clear that supporting more platforms means having to deal with specific browser&#8217;s issues that may lead to more work to be done in order to maintain the library. Moreover, these libraries have a small size as one of its main constraints.</p><p>However, take into account that most recent versions of Internet Explorer and Opera Mobile have a similar feature set to the webkit&#8217;s one, and adding support to them could be quite easy.</p><p>Having a look at their source code, I have seen that some libraries rely on non-standard features, like proprietary property <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/proto">__proto__</a>, to provide a chain-able API and add custom functions like addClass or removeClass to an element, or ready to a document.</p><p>Take <a href="https://github.com/madrobby/zepto/blob/master/src/zepto.js#L74">zepto.js as an example</a>:</p><pre class="brush: jscript; highlight: [3]; title: ; notranslate">
function Z(dom, selector){
    dom = dom || emptyArray;
    dom.__proto__ = Z.prototype;
    dom.selector = selector || '';
    return dom;
}
</pre><p>The usage of __proto__ to extend the DOM element by modifying the prototype chain doesn&#8217;t work on IE or Opera, as a user <a href="https://github.com/madrobby/zepto/issues/272">already pointed out</a>.</p><p>This is an approach to avoid <a href="http://perfectionkills.com/whats-wrong-with-extending-the-dom/">extending the DOM</a>, defining every helper method in every retrieved DOM element, or implementing a wrapper around an HTMLElement like jQuery does with its jQuery object, but only supporting Gecko and Webkit browsers.</p><h2>A tip for webapps developers</h2><p>I would like to tell developers that they should try to go the extra mile and consider supporting non-webkit mobile browsers. Definitely, manufacturers like Nokia are betting on WP7 (you only have to see their <a href="http://thenokiablog.com/2012/01/04/nokia-lumia-900-100-million/">Lumia 800 ad campaign</a>) and we could see an increase in IE mobile share. In addition, as browsers other than the default one can be installed on some devices like Android ones, opening the door to Opera Mobile and Firefox, we can&#8217;t be sure that an Android user will be using a webkit browser.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2012/01/webkit-only-mobile-js-libraries/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Tuenti mobile on Barcelona Developers Conference</title><link>http://blog.josemanuelperez.es/2011/11/tuenti-mobile-barcelona-developers-2011-davide-mendolia/</link> <comments>http://blog.josemanuelperez.es/2011/11/tuenti-mobile-barcelona-developers-2011-davide-mendolia/#comments</comments> <pubDate>Wed, 09 Nov 2011 12:55:44 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[conference]]></category> <category><![CDATA[speech]]></category> <category><![CDATA[tuenti]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=476</guid> <description><![CDATA[I am happy to announce that my workmate Davide Mendolia (@davideme) will be offering a speech about Tuenti Mobile during the Barcelona Developers Conference 2011 on Saturday, November 19. Since I joined Tuenti on February, I have been able to explore mobile web site development in depth, facing a world of devices and different capabilities [...]]]></description> <content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-488" title="Tuenti mobile site" src="http://blog.josemanuelperez.es/wp-content/uploads/2011/11/tuenti-mobile-site-150x150.jpg" alt="" width="150" height="150" />I am happy to announce that my workmate Davide Mendolia (<a href="http://twitter.com/davideme">@davideme</a>) will be offering <a href="http://bcndevcon.org/en/node/209">a speech about Tuenti Mobile</a> during the Barcelona Developers Conference 2011 on Saturday, November 19.</p><p>Since I joined Tuenti on February, I have been able to explore mobile web site development in depth, facing a world of devices and different capabilities that makes programming a real challenge. As the use of mobile devices is growing, so we are making an effort to adapt Tuenti mobile site to offer the best possible user experience.</p><p>If you are around Barcelona and you are interested in mobile development don&#8217;t hesitate to attend the conference.</p><p>Tuenti will be represented also by <a href="http://kartones.net/blogs/kartones/">Diego Kartones</a> (<a href="http://twitter.com/kartones">@kartones</a>) who will be speaking about <a href="http://bcndevcon.org/en/content/tuenti-release-workflow">Tuenti release workflow</a> and there will also be <a href="http://bcndevcon.org/en/content/tuenti-security">a talk about security</a>.</p><div style="background-color: #f5f5f5; padding: 5px;">​<a href="http://bcndevcon.org/en/node/209"><span>Discover Tuenti mobile development</span></a><br /> <span>Nov 19, 9:30AM</span>—<span>Nov 19, 10:15AM</span><br /> ​<span>​<span>Museu Marítim de Barcelona</span>​<span> &#8211; <span>Avinguda Drassanes, s/n</span>, <span>Barcelona</span>, <span>Spain</span></span><br /> </span></div> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/11/tuenti-mobile-barcelona-developers-2011-davide-mendolia/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Server Sent Events on iOS</title><link>http://blog.josemanuelperez.es/2011/08/server-sent-events-iphone/</link> <comments>http://blog.josemanuelperez.es/2011/08/server-sent-events-iphone/#comments</comments> <pubDate>Mon, 08 Aug 2011 19:13:31 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[ipad]]></category> <category><![CDATA[iphone]]></category> <category><![CDATA[polling]]></category> <category><![CDATA[server sent events]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=466</guid> <description><![CDATA[Server Sent Events are fired on iOS even when the page is not active. Are there any good applications for this?]]></description> <content:encoded><![CDATA[<p>You have probably heard about websockets, which promise to be a better  alternative to short and long polling to achieve real time updated  websites. But maybe you didn&#8217;t know about <strong>server sent events</strong>. They are nice to send information from server to client using the same server  technology you probably have, using a lighter approach than polling.</p><p><a href="http://www.html5rocks.com/en/tutorials/eventsource/basics/">Here you can find a nice explanation</a>, and you can give it a try by visiting this <a href="http://html5.firejune.com/demo/sse.html">Server-sent Event Demo</a> from a capable browser.</p><h2>How iOS devices react to Server Sent Events</h2><div id="attachment_470" class="wp-caption alignleft" style="width: 210px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/08/server-sent-events-iphone.png"><img class="size-medium wp-image-470" title="Server Sent Event on iPhone" src="http://blog.josemanuelperez.es/wp-content/uploads/2011/08/server-sent-events-iphone-200x300.png" alt="" width="200" height="300" /></a><p class="wp-caption-text">SSE will fire on iOS even if the page is not active</p></div><p>Having a look at how iPhone behaves when using Server Sent Events I  realized that even if the tab showing a page using SSE is not the  active one, Server Sent Events are processed. In short, events are  processed as long as that page is loaded in any tab, no matter if it  focused or not, and even after Safari is closed using Home button or the  device is locked using the top button. The difference is that only when using Safari, a loading spinner is shown on top.</p><p>The behaviuor of iPad is quite similar. It also processes SSE when it is locked or when a different tab is active, but it won&#8217;t process them when closing Safari.</p><p>Is this how iPhone and iPad should behave? <a href="http://dev.w3.org/html5/eventsource/">According to W3C</a>, yes. They state:</p><blockquote><p>The &#8220;push proxy&#8221; service uses a technology such as OMA push to convey   the event to the mobile device, which wakes only enough to process the   event and then returns to sleep.</p></blockquote><p>But I can&#8217;t  find how this can be useful at all. If only a notification system was  available, a chat application could be implemented and notify the user  whenever other person in the chat mentions him. But currently there&#8217;s no way a  non-active page can react to a server sent event, thus no useful event processing.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/08/server-sent-events-iphone/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Web technologies behind Google+</title><link>http://blog.josemanuelperez.es/2011/07/google-plus-technology-overview/</link> <comments>http://blog.josemanuelperez.es/2011/07/google-plus-technology-overview/#comments</comments> <pubDate>Sat, 02 Jul 2011 18:59:19 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[google]]></category> <category><![CDATA[google plus]]></category> <category><![CDATA[web development]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=448</guid> <description><![CDATA[What web technologies are behind Google+ website? This is a collection of links to posts explaining interesting features of this brand new network site.]]></description> <content:encoded><![CDATA[<p>We are all excited about the Google+ release, and this is a nice opportunity for web developers to find out how some of its more interesting features have been implemented.</p><p>I am trying to collect information about implementation details for every innovative functionality that makes Google+ push the limits of web development.</p><p>Meanwhile I am trying to get useful conclusions by seeing their CSS and JavaScript code and the flow of HTTP requests. Until now I haven&#8217;t seen especial things involving static resources like images (not using <a href="http://code.google.com/speed/webp/">WebP</a>), CSS or JavaScript files. I can only say that CSS and JavaScript files are greatly minified, squishing their content to the last byte.</p><p><span style="color: #000000; font-size: 23px; line-height: 35px;">Feedback system</span></p><p>Google Plus feedback system is brilliant. It is very easy to use for low-tech users thanks to their highlight / black out feature and area selection, and useful for Google due to the information they retrieve from the browser, HTML structure and javascript log.</p><div id="attachment_451" class="wp-caption aligncenter" style="width: 650px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/07/feedback-test.jpg"><img class="size-large wp-image-451" title="Creating a feedback message in Google+" src="http://blog.josemanuelperez.es/wp-content/uploads/2011/07/feedback-test-1024x572.jpg" alt="" width="640" height="357" /></a><p class="wp-caption-text">Creating a feedback message in Google+, blacking out and highlighting certain areas</p></div><p>I find it very interesting how they are taking a screenshot of the web page when you preview the feedback message:</p><div id="attachment_450" class="wp-caption aligncenter" style="width: 581px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/07/feedback-test-preview.jpg"><img class="size-full wp-image-450" title="Preview of a feedback message in Google+" src="http://blog.josemanuelperez.es/wp-content/uploads/2011/07/feedback-test-preview.jpg" alt="" width="571" height="770" /></a><p class="wp-caption-text">Preview of a feedback message in Google+, showing a screenshot of the web page</p></div><p>There exist tools like <a href="http://html2canvas.hertzen.com/">html2canvas</a> that allows the creation of screenshots by reading the DOM tree and applying CSS rules.</p><p>More info:</p><ul><li><a href="http://stackoverflow.com/questions/6527742/how-does-the-screenshot-part-of-the-google-feedback-system-work">How does the Screenshot part of the Google+ Feedback system work?</a></li></ul><h2>Google Circle animation</h2><p>It is nice how fluid the interface is when creating circles and dragging people into them. The animations are very smooth and it is a pleasure to use it, making something that was tedious a fun experience.</p><p>More info:</p><ul><li><a href="http://www.quora.com/Is-the-Google+-circle-animation-implemented-in-JavaScript-or-Flash">Is the Google+ circle animation implemented in JavaScript or Flash?</a></li></ul><h2>Google Hangout</h2><p>This is a feature that extends Google Talk video chat to make it possible to video chat with up to 10 people. This represents a big effort in terms of bandwidth and lag avoidance.</p><p>More info:</p><ul><li><a href="http://gigaom.com/video/google-hangouts-technology">The technology behind Google+ Hangouts</a></li></ul><h2>Accessibility</h2><p>The use of ARIA attributes in the HTML code (aria-haspopup, aria-owns, aria-owner) makes me thing they have take accessibility as a priority. This is in line with their effort for spreading the word about  developing accessible websites, as they explained in their talk <a href="http://www.google.com/events/io/2011/sessions/creating-accessible-interactive-web-apps-using-html5.html">Creating Accessible Interactive Web Apps using HTML5</a> in the recent Google I/O 2011 conference.</p><h2>JSON responses forcing AJAX calls</h2><p>If you inspect the JSON responses content, you will see that they start with</p><blockquote><p>)]}&#8217;</p></blockquote><p>This seems a way to force requests to be made using Ajax calls and avoid retrieving data using script tags, that would result in a error being thrown. This is similar as how facebook adds an infinite loop to their JSON responses using</p><blockquote><p>for (;;);</p></blockquote><p>More info:</p><ul><li><a href="http://stackoverflow.com/questions/6618441/strange-json-response-in-google-plus">Strange JSON response in Google Plus</a></li></ul><div><span style="font-size: small;"><span style="line-height: 24px;"><br /> </span></span></div><h2>Indexability</h2><p>Try to disable JavaScript and you&#8217;ll see that you can&#8217;t even log in Google+. However, public profiles (make a <a href="http://www.google.es/search?q=site:plus.google.com">basic search for site:plus.google.com</a>) work quite well when disabling JavaScript. Tabs link to pages where content is loaded correctly, except for Photos and Videos tabs, so that search engines can view and index the most important part of the profile information.</p><p>Google has even add <a href="http://searchenginewatch.com/article/2082771/Deconstructing-Google">a parameter to look for Google+ profile pages</a>.</p><h2>Tools used to implement Google+</h2><p>Google+ has been implemented using a set of tools that are mostly open source. In the server side, they use Java Servlets, <a href="http://en.wikipedia.org/wiki/BigTable">BigTable</a> and <a href="http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf">Colossus</a>. Google+ seems to be using GSE (<a href="http://code.google.com/p/opengse/">Google Servlet Engine</a>) according to the &#8216;Server&#8217; response header when requesting the root page.</p><p>And in the client side, they use <a href="http://code.google.com/closure/">Closure</a>.</p><p>More info:</p><ul><li><a href="http://highscalability.com/blog/2011/7/12/google-is-built-using-tools-you-can-use-too-closure-java-ser.html">Google+ is Built Using Tools You Can Use Too: Closure, Java Servlets, JavaScript, BigTable, Colossus, Quick Turnaround</a></li><li><a href="http://anyasq.com/79-im-a-technical-lead-on-the-google+-team">I&#8217;m a technical lead on the Google+ team. Ask me anything.</a></li><li><a href="http://stackoverflow.com/questions/6545811/google-social-network-in-depth">Google+ social network in depth</a></li></ul><p>Have you come across some Google+ implementation detail that should be highlighted? Don&#8217;t hesitate to comment to this post!</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/07/google-plus-technology-overview/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Avoid showing address bar on iPhone when loading ajax</title><link>http://blog.josemanuelperez.es/2011/06/prevent-iphone-navigation-bar-ajax-link-click/</link> <comments>http://blog.josemanuelperez.es/2011/06/prevent-iphone-navigation-bar-ajax-link-click/#comments</comments> <pubDate>Sat, 11 Jun 2011 18:28:08 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[facebook]]></category> <category><![CDATA[ios]]></category> <category><![CDATA[iphone]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[mobile]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=433</guid> <description><![CDATA[Workaround to avoid showing the loading address bar when loading ajax content on iPhone.]]></description> <content:encoded><![CDATA[<p>You can find a <a href="http://josemanuelperez.es/links.html" target="_blank">demo showing the default behaviour and the one using Facebook&#8217;s technique</a>. Use an iPhone or iPod Touch to see the effect.</p><p>When clicking a link for ajax navigation on iPhone and iPod Touch, the navigation bar slides down and up for every link, even when they are enhanced to support ajax navigation and its click event is captured and we load content using XMLHttpRequest instead.</p><p>This is a bit annoying and some developers have already tried to solve it. See these links:</p><ul><li><a href="http://stackoverflow.com/questions/1788605/can-iphone-safari-be-prevented-from-showing-the-navigation-bar-during-an-ajax-cal">Can iPhone Safari be prevented from showing the navigation bar during an AJAX call?</a></li><li><a href="https://forum.jquery.com/topic/ios-urlbar-shows-then-hides-when-clicking-internal-link">iOS urlbar shows then hides when clicking internal link</a></li><li><a href="https://forum.jquery.com/topic/stopping-the-url-bar-from-dropping-down-i-discovered-a-workaround">Stopping the url bar from dropping down &#8211; I discovered a workaround</a></li><li><a href="http://forum.jquery.com/topic/how-do-i-stop-mobile-safari-from-dropping-down-its-url-loading-bar-whenever-i-submit-an-ajax-request">How do i stop mobile safari from dropping down its URL/Loading bar whenever i submit an ajax request?</a></li></ul><p>The fact of having an anchor with an href attribute is enough for Safari Mobile to show the bar unless the address is preceded by the hash sign. It is not the fact of changing the URL, because if you preventDefault() the click on the link and avoid the navigation, the bar is shown anyway.</p><p>I realized that Facebook, among others sites with iPhone adapted versions (see jQtouch, Sencha Touch or Twitter), didn&#8217;t show that bar dropping from the top of the screen.</p><p>Looking at Facebook&#8217;s mobile site code, I found out that they made a workaround. They attach to the touchend event, which is fired before the click event fires, and then replace the value of the href attribute:</p><pre class="brush: jscript; title: ; notranslate">
JX.install(&quot;MLinkHack&quot;, {initialize:function() {
  if(!JX.MTouchClick.hasTouchEvents()) {
    return
  }
  JX.Stratcom.listen(&quot;touchend&quot;, &quot;tag:a&quot;, function(a) {
    var c = a.getNode(&quot;tag:a&quot;);
    if(c.getAttribute(&quot;target&quot;) == &quot;_blank&quot;) {
      return
    }
    var b = c.getAttribute(&quot;href&quot;);
    if(!b || b.indexOf(&quot;#&quot;) === 0) {
      return
    }
    var d = JX.$U(b).getProtocol();
    if(d &amp;&amp; d !== &quot;http&quot; &amp;&amp; d !== &quot;https&quot;) {
      return
    }
    JX.MLinkHack.add(c)
  })
}, statics:{_hack:&quot;#!&quot;, add:function(a) {
  a.setAttribute(&quot;href&quot;, JX.MLinkHack._hack + a.getAttribute(&quot;href&quot;))
}, remove:function(b) {
  var a = b.getAttribute(&quot;href&quot;);
  a = a.indexOf(JX.MLinkHack._hack) === 0 ? a.substr(2) : a;
  b.setAttribute(&quot;href&quot;, a)
}}});
</pre><p>Later, the href value is set back to its original value, calling to the <code>JX.MLinkHack.remove()</code> method:</p><pre class="brush: jscript; title: ; notranslate">
JX.behavior(&quot;m-link&quot;, function() {
  ...
  JX.Stratcom.listen(&quot;click&quot;, &quot;tag:a&quot;, function(event) {
    if(JX.Stratcom.pass()) {
      return
    }
    try {
      var e = event.getRawEvent();
      var link = event.getNode(&quot;tag:a&quot;);
      if(link.getAttribute(&quot;onclick&quot;) || (e.which || e.button) &gt;= 2) {
        return
      }
      if(window.FW_BFF_ENABLED) {
        event.kill();
        FWBff.send(&quot;/fb/onclick&quot;, [link.getAttribute(&quot;href&quot;), link.getAttribute(&quot;target&quot;)]);
        return
      }
      if(window.user_action) {
        user_action(link, &quot;a&quot;, e)
      }
      JX.MLinkHack.remove(link);
      var href = link.getAttribute(&quot;href&quot;);
      ...
});
</pre><p>As we see, this is only done for touch devices. Non-touch devices see normal links, so we can provide the default navigation for the rest of devices. That is nice for our progressive enhancement approach.</p><p>This workaround works nice when applied to a hash based ajax navigation. In addition, if we want to use History API, then we could call to history.pushState() in the click event, once we have replaced the href to its original value. That way we would use the hash as a temporary hack to prevent Safari browser from showing the bar.</p><p>I will try to check the techniques that other sites have implemented to solve this, but they might be similar to this one.</p><p>And I find this less hacky than using a &#8216;link&#8217; attribute instead of &#8216;href&#8217; attribute in anchors, or replace anchors by buttons, as I&#8217;ve read in some place.</p><p>Want to see it in action? <a href="http://josemanuelperez.es/links.html" target="_blank">See the demo</a>.</p><p>EDIT: It seems that jQuery Mobile has managed to implement this in their <a href="http://jquerymobile.com/blog/2011/06/20/jquery-mobile-beta-1-released/">beta 1.0</a></p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/06/prevent-iphone-navigation-bar-ajax-link-click/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>BigPipe in ASP.Net MVC using Razor</title><link>http://blog.josemanuelperez.es/2011/05/bigpipe-in-asp-net-mvc-using-razor/</link> <comments>http://blog.josemanuelperez.es/2011/05/bigpipe-in-asp-net-mvc-using-razor/#comments</comments> <pubDate>Sun, 22 May 2011 11:55:24 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[asp.net mvc]]></category> <category><![CDATA[bigpipe]]></category> <category><![CDATA[razor]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=422</guid> <description><![CDATA[Razor to implement BigPipe using ASP.Net MVC. You can use the new view engine to early flush pagelets content and mimic this technique created by Facebook.]]></description> <content:encoded><![CDATA[<p>It&#8217;s been some time since I posted the tutorial to implement <a href="http://blog.josemanuelperez.es/2010/09/tutorial-how-to-implement-bigpipe-using-asp-net-mvc-part-1/">Facebook&#8217;s BigPipe using Microsoft ASP.Net MVC</a>. And since then, Razor view engine has increased its presence for providing a way to implement cleaner views and make it easy to avoid ending up with spaguetti code.</p><p>Though now I am focused on PHP, in my previous job we decided to migrate to Razor as soon as possible since it is a more convenient way to implement ASP.NET MVC views, while you can keep your models and controllers code the same.</p><p>However, Razor does not behave well with the proposed BigPipe solution due to its way of managing the partial views code. You can&#8217;t write to the output in your inner views using Response.Write() nor flush because Razor renders pages from inside out. Thus, the inner most view is rendered and written to a buffer, and then the partial view / content place holder where it is defined, and so, until the outer most layout is reached. Then, the content of the buffer is written and flushed to the browser.</p><p>This provides the developer interesting new patterns. For instance, you can import JavaScript or CSS files depending on the content rendered in the views, and import them in the head section of your page, since when the layout is reached, we already know which dependencies to load to provide the functionality needed by the different elements of the page.</p><p>Some days ago I received a meesage from <strong>James Hull</strong> (<a href="http://twitter.com/bigfellahull">@bigfellahull on twitter</a>) explaining a way to achieve BigPipe using Razor.</p><h2>Pagelets containers</h2><p>The way to define a pagelet container is the same. Just write the container out to the buffer and all is well.</p><pre class="brush: csharp; title: ; notranslate">
helper.ViewContext.Writer.Write(&quot;div id=\&quot;&quot; + pagelet.Container + &quot;\&quot;&lt;/div&gt;&quot;);
</pre><h2>Early flushing</h2><p>However, to perform the early flush and flushing each pagelet required a little thinking. James has been looking for a solution and he found out that the best approach is to manually write the buffer to the response.</p><p>So, in the layout (master) page, we can cast the ViewContext.Writer buffer to a string writer and then get the underlining string builder. Then you can write this string builder to the response, flush it and set the string builder&#8217;s length to 0. This seems to be what razor does under the covers so we are just doing it a little earlier.</p><pre class="brush: csharp; title: ; notranslate">
var sb = ((StringWriter)ViewContext.Writer).GetStringBuilder();
Response.Write(sb);
Response.Flush();
sb.Length = 0;
Html.ExecutePagelets();
</pre><p>We can do the same with the pagelets,</p><pre class="brush: csharp; title: ; notranslate">
lock (_locker) {
  helper.ViewContext.Writer.Write(pagelet.Serialise());
  var sb = ((StringWriter)helper.ViewContext.Writer).GetStringBuilder();
  helper.ViewContext.HttpContext.Response.Write(sb);
  helper.ViewContext.HttpContext.Response.Flush();
  sb.Length = 0;
}
</pre><p>And now it works fine in razor!</p><p>I am really happy that James (<a href="http://twitter.com/bigfellahull">@bigfellahull</a>) has been researching a way to port this technique to Razor, that is called to be the <em>de facto</em> ASP.Net view engine.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/05/bigpipe-in-asp-net-mvc-using-razor/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Changing job</title><link>http://blog.josemanuelperez.es/2011/02/changing-job/</link> <comments>http://blog.josemanuelperez.es/2011/02/changing-job/#comments</comments> <pubDate>Sat, 12 Feb 2011 10:21:14 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[signum framework]]></category> <category><![CDATA[signum software]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=414</guid> <description><![CDATA[This week I made a job change, from Signum Software to Tuenti Technologies. Working at Signum Software I have met a group of very professional people and I learnt a lot from them. It is a pleasure to work at a company that takes care of their own products, always trying to improve them. And [...]]]></description> <content:encoded><![CDATA[<p>This week I made a job change, from <a href="http://signumsoftware.com">Signum Software</a> to <a href="http://www.tuenti.com">Tuenti Technologies</a>.</p><p>Working at Signum Software I have met a group of very professional people and I learnt a lot from them. It is a pleasure to work at a company that takes care of their own products, always trying to improve them. And for a developer it&#8217;s even better when that product is a complete framework that optimizes and makes your work easier.</p><p>If you are willing to carry out a .Net project, you&#8217;d better have a look at Signum Framework. Version 2 will be soon released, and lots of new features will be presented. You can follow them on <a href="http://twitter.com/signumframework">twitter @signumframework</a> to get last news, and extendend documentation is available on <a href="http://www.signumframework.com">signumframework.com</a>. For a quick overview you can read <a href="http://en.wikipedia.org/wiki/Signum_Framework">Wikipedia&#8217;s article about Signum Framework</a>.</p><p>I wish Signum the best of luck, and I hope more developers realize how Signum Framework can improve their projects development, manageability and maintainability.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/02/changing-job/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Front End Tech Talk &#8211; Facebook</title><link>http://blog.josemanuelperez.es/2011/01/talk-facebook-frontend-javascript/</link> <comments>http://blog.josemanuelperez.es/2011/01/talk-facebook-frontend-javascript/#comments</comments> <pubDate>Sun, 30 Jan 2011 17:29:22 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[bootloader]]></category> <category><![CDATA[facebook]]></category> <category><![CDATA[frontend]]></category> <category><![CDATA[haste]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[primer]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=397</guid> <description><![CDATA[Nice ideas taken from Facebook's Front End Tech Talk about implementing common interactions and patterns to reduce Javascript file size and use progressive enhancement.]]></description> <content:encoded><![CDATA[<p>Yesterday I watched this <a href="http://www.facebook.com/video/video.php?v=596368660334">Front End Tech Talk by Facebook</a>. I found it very interesting because they explained how they faced the problem of having a lot of javascript code and how they managed to reduce it. I think this can be applied not only to a website of the size of Facebook&#8217;s, but also any other project where we could refactor existing code.</li></ul><blockquote><p>We had about 1MB of JS on the homepage</p></blockquote> <figure><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/facebook-1mb-javascript.jpg"><img class="aligncenter size-large wp-image-398" title="Facebook - Too much JS" src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/facebook-1mb-javascript-1024x574.jpg" alt="We had about of 1MB of JS on the homepage" width="640" height="358" /></a></figure><p>They realized they had a problem with so much JS code and they worked at different levels to shrink it.</p><h2>Haste</h2><p>Haste is a package and dependy manager for CSS and JS files. In each file they specify the name of the package provided by the file and those files that are required to run the file. Thus, Haste can manage what files are needed to run a certain script.</p><p>This helps managing how files are requested and even which sets of files should be merged. This system was further explained by <a href="http://davidwei.org/cv/talks/">Xiaoliang &#8220;David&#8221; Wei</a> at his talk about <a href="https://encrypted.google.com/url?sa=t&amp;source=web&amp;cd=1&amp;ved=0CCAQFjAA&amp;url=http%3A%2F%2Fvelocity.oreilly.com.cn%2Fppts%2FVelocityChina2010Dec7StaticResource.pdf&amp;ei=OotFTem1LdG28QPP8IivCQ&amp;usg=AFQjCNHGcAAUXVA1xVsEruRUaiIFjMoF7g&amp;sig2=xpRER8Mkl1ets3epRsSt8A"><em>Static resource management &amp; optimization</em></a> that took place on December 2010 at Velocity China.</p><h2>Bootloader</h2><p>This consists of a JS library that helps loading and unloading static resources on demand. Not too far of RequireJS or LabJS. It uses dynamic script injection and executes a callback function once the resource is loaded.</p><p>The good point is that you can even suggest static resources that are not inmediately needed but could be prefetched at background.</p><h2 id="primer">Primer</h2><p>Makinde Adeagbo <a href="http://jsconf.blip.tv/file/3839676/">already talked about Primer at JSConf 2010</a> (<a href="http://www.slideshare.net/makinde/javascript-primer">slides</a>).</p><p>A waterfall analysis showed that CSS resources where requested quite at the bottom and a lot of javascript on the head. Moving Javascript code to the bottom showed that the user interface would freeze while downloading/parsing/executing this code and that would provide a bad user experience. In some way, this is quite similar to what Yahoo! also found out, and I explained on my <em><a href="/2010/12/yahoo-tips-website-performance-flush-bottom/">The not so good performance tips</a></em> post.</p><p>They decided to rewrite their JS code so that they could load a small file at the top that would provide the common functionality needed (about 80% of the interactions). And they moved Javascript client code to PHP code on the server. Instead of calling to a function like this one:</p><div id="attachment_401" class="wp-caption aligncenter" style="width: 650px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/prev-dialog-code.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/prev-dialog-code-1024x574.jpg" alt="" title="Before Primer" width="640" height="358" class="size-large wp-image-401" /></a><p class="wp-caption-text">Javascript code to build a dialog</p></div><p>they rewrote dialogs as anchors with a rel=&#8221;dialog&#8221; attribute:<br /><div id="attachment_401" class="wp-caption aligncenter" style="width: 650px">Javascript code to build a dialog&#8221;]<a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/after-dialog-code.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/after-dialog-code-1024x574.jpg" alt="" title="Dialog link using Primer" width="640" height="358" class="aligncenter size-large wp-image-402" /></a><p class="wp-caption-text">Simplified code to mark a link as a dialog</p></div></p><p>Basically they embraced progressive enhancement. This dialog links would be ajaxified later using a common Javascript code:</p><div id="attachment_401" class="wp-caption aligncenter" style="width: 650px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/after-dialog-code-common.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/after-dialog-code-common-1024x573.jpg" alt="" title="Adding dialog behavior using Javascript" width="640" height="358" class="aligncenter size-large wp-image-403" /></a><p class="wp-caption-text">Adding a listener to manage click events on links marked as dialogs</p></div><p>And instead of letting Javascript set the title, content and the rest of dialog properties, it is the server the one that serves the dialog formatted as needed.</p><div id="attachment_401" class="wp-caption aligncenter" style="width: 650px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/dialog-server-code.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/dialog-server-code-1024x574.jpg" alt="" title="PHP code to generate a dialog" width="640" height="358" class="aligncenter size-large wp-image-404" /></a><p class="wp-caption-text">PHP chainable code to create a dialog and set different properties</p></div><p>It is like converting a jQuery widget plugin into an ajax call and let the server generate the widget content.</p><p>They used this same approach to replace chunks of similar Javascript code. In async calls that retrieved html to replace existing markup, they are now generating javascript code (using PHP) on the server side and executing it in the async response. And if the url that should be requested when clicking an ajaxified link is a different one, they specify it using a custom <code>ajaxify</code> attribute. They also use this <code>ajaxify</code> attribute to specify that a form should be ajaxified.</p><p>Like Makindo says,</p><blockquote><p>if you are writing a site with tons and tons of Javascript it is very easy to forget about actual forms</p></blockquote><p>All this common interactions are shown in the comments form:<br /><div id="attachment_405" class="wp-caption aligncenter" style="width: 650px"><a href="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/application-comment-form.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2011/01/application-comment-form-1024x573.jpg" alt="" title="Facebook&#039;s comment form" width="640" height="358" class="size-large wp-image-405" /></a><p class="wp-caption-text">An example of common interactions that in their comment form</p></div></p><p>The top red arrow indicates that Comment is a label, so clicking on it focuses the comment textarea.</p><p>Some sample Javascript code is available on <a href="https://gist.github.com/376039">https://gist.github.com/376039</a>.</p><p>They managed to not only reduce Javascript size, but loading CSS aton the top and being able to load Javascript at the bottom in an async mode.</p><p>This talk shows that sometimes it is necessary to return to the basic elements and build interactions from there, trying to find common functionality to reduce the code needed, and embracing progressive enhancement as a way to achieve it.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2011/01/talk-facebook-frontend-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>The not so good web performance tips</title><link>http://blog.josemanuelperez.es/2010/12/yahoo-tips-website-performance-flush-bottom/</link> <comments>http://blog.josemanuelperez.es/2010/12/yahoo-tips-website-performance-flush-bottom/#comments</comments> <pubDate>Tue, 28 Dec 2010 19:46:41 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[flush]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[yahoo]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=383</guid> <description><![CDATA[Yesterday I was reading Zakas&#8217; Performance on the Yahoo! Homepage slideshare presentation, and I got very surprised when I saw that Yahoo had realized that two of the wide accepted tips for improving website performance had not work so well for them. 1) Put scripts at the bottom (slide 37) Or at least that is [...]]]></description> <content:encoded><![CDATA[<p><a href="http://blog.josemanuelperez.es/wp-content/uploads/2010/12/yahoo-homepage.jpg"><img src="http://blog.josemanuelperez.es/wp-content/uploads/2010/12/yahoo-homepage-300x212.jpg" alt="" title="Yahoo! Homepage" width="300" height="212" class="alignright size-medium wp-image-388" /></a><br /> Yesterday I was reading <a href="http://www.slideshare.net/nzakas/performance-yahoohomepage">Zakas&#8217; Performance on the Yahoo! Homepage slideshare presentation</a>, and I got very surprised when I saw that Yahoo had realized that two of the wide accepted tips for improving website performance had not work so well for them.</p><p><strong>1) Put scripts at the bottom</strong> (slide 37)<br /> Or at least that is <a href="http://developer.yahoo.com/performance/rules.html#js_bottom">what Yahoo recommends</a>, and it contributes as one of the indicators to calculate YSlow score. But they found out that page would stay frozen while fetching, executing and parsing Javascript and this was worse over slow connections.</p><p>The solution was loading Javascript using dynamic <code>script</code> tags. This solution is better applied when using progressive enhancement because users can try to perform actions that are provided by this non-blocking javascript.</p><p><strong>2) Flush after head</strong> (slide 51)<br /> This is another <a href="http://developer.yahoo.com/performance/rules.html#flush">recommended practice by Yahoo</a>. They found out that the best solution was to flush at different points, especially when a block of a considerable size had been output. They also recommend to avoid having a big external <code>div</code> containing the different sections, and place directly the sections as <code>body</code> children.</p><p>In conclusion, the best you can do is test the different alternatives, especially when trying to find the one the provides the best user&#8217;s preception page load time.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2010/12/yahoo-tips-website-performance-flush-bottom/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>AsyncController: Server-side parallelism</title><link>http://blog.josemanuelperez.es/2010/12/asp-net-mvc-async-controller/</link> <comments>http://blog.josemanuelperez.es/2010/12/asp-net-mvc-async-controller/#comments</comments> <pubDate>Fri, 24 Dec 2010 16:28:37 +0000</pubDate> <dc:creator>JMPerez</dc:creator> <category><![CDATA[General]]></category> <category><![CDATA[asp.net mvc]]></category> <category><![CDATA[async]]></category> <category><![CDATA[asynccontroller]]></category><guid isPermaLink="false">http://blog.josemanuelperez.es/?p=379</guid> <description><![CDATA[I usually face asynchroronus WPO from the browser side, for instance making async requests to include Javascript files or AJAX-requesting any other content. Today I have come across a feature that has been around since ASP.Net MVC 2 and that allows Asynchronous processing of controller actions. It is nicely explained on Using an Asynchronous Controller [...]]]></description> <content:encoded><![CDATA[<p>I usually face asynchroronus WPO from the browser side, for instance making async requests to include Javascript files or AJAX-requesting any other content.</p><p>Today I have come across a feature that has been around since ASP.Net MVC 2 and that allows Asynchronous processing of controller actions. It is nicely explained on <a href="http://msdn.microsoft.com/en-us/library/ee728598.aspx">Using an Asynchronous Controller in ASP.NET MVC</a> on MSDN website.</p><p>It is very useful on long-running requests, since it avoids thread-blocking while the request is being processed. In addition, it exposes AsyncManager, that can be used to increase parallelism in an action by splitting the execution of independent operations.</p> ]]></content:encoded> <wfw:commentRss>http://blog.josemanuelperez.es/2010/12/asp-net-mvc-async-controller/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching using disk: basic
Object Caching 517/643 objects using disk: basic

Served from: blog.josemanuelperez.es @ 2012-02-06 07:05:20 -->
