<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Marfeel Labs - Medium]]></title>
        <description><![CDATA[Marfeel is an ad tech platform that revolutionizes the way publishers create, optimize and monetize mobile websites. These are the engineers and their stories that make the magic happen. - Medium]]></description>
        <link>https://medium.com/marfeel-labs?source=rss----401dbc33916d---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Marfeel Labs - Medium</title>
            <link>https://medium.com/marfeel-labs?source=rss----401dbc33916d---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:54:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/marfeel-labs" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Marfeel CMP: A Frontend Development Odyssey in the Realm of GDPR]]></title>
            <link>https://medium.com/marfeel-labs/marfeel-cmp-a-frontend-development-odyssey-in-the-realm-of-gdpr-d4cc839d9083?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/d4cc839d9083</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[gdpr]]></category>
            <category><![CDATA[preact]]></category>
            <category><![CDATA[content-management]]></category>
            <dc:creator><![CDATA[Marfeel Labs]]></dc:creator>
            <pubDate>Fri, 05 Oct 2018 15:12:41 GMT</pubDate>
            <atom:updated>2018-10-05T15:32:21.950Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*A5FMTjxUDXJ2Zgf0suVpjg.png" /></figure><p><em>Written by Gianmarco | Product Frontend Developer</em></p><p>Let’s be real.</p><p>From 1 to 10, how sick are you of the dozens of “We value your privacy” pop-ups you encounter day after day as you’re striving to, say, read some news on any website?</p><p>And, on the same scale, how much did your awareness increase in regards to how your personal data is managed within this or that website, since this bunch of pixels started to get in the way of you and the content you want to access?</p><p>While you ponder these questions, you may know that — as of May 25 — publishers, advertisers, and the whole ecosystem of businesses which make direct or indirect use of personal data have been forced to dig deep into the plot of the European General Data Protection Regulation.</p><p>Now, <em>compliance</em> is the key aspect also for the technical development of software solutions (Consent Management Platforms or CMP) to gather the consent of the users in order to handle their personal data on the web. The issue is that to be effective <em>and </em>law-compliant, a CMP should meet a set of requirements which can be hard to combine: functional completeness, informational completeness, and ease of interaction.</p><p>And here is where the odyssey of frontend development starts.</p><h3><strong>Just a pop-up? The ingredients of an impossible recipe.</strong></h3><p>A Consent Management Platform represents the middleman between a user and the proposer of web-content of some sort who may make use of personal information directly (e.g. sampling data from a newsletter subscription) or indirectly (e.g. selling data to third-party vendors for monetization purposes). Its main functional goals are two and user-centric:</p><ol><li>Having the users know how such data could be used while consuming or interacting with the contents of a website, in terms of well-defined purposes and vendors who endorse them.</li><li>Getting the explicit approval or rejection from the users to actually use that data.</li></ol><p>From a technical standpoint, such goals are achieved through the development of a stand-alone software item which mainly relies on frontend technology and endorses characteristics that are common to all the CMP’s.</p><p>To start with, all the CMP’s expose a common core JS API which is built on top of the <a href="https://github.com/InteractiveAdvertisingBureau/GDPR-Transparency-and-Consent-Framework/blob/master/CMP%20JS%20API%20v1.1%20Final.md">IAB Transparency and Consent Framework JS specification</a>. As users express their preferences through the CMP’s UI, this gets encoded into a <a href="https://github.com/InteractiveAdvertisingBureau/Consent-String-SDK-JS"><em>consent string</em></a><em> </em>that will then be accessible by web-content providers and vendors through the public API to know how to behave in terms of advertisement targeting, data tracking, etc.</p><p>Speaking of UI and UX, GDPR-compliance is a mission that can offer some nightmares: A CMP needs to expose the <a href="http://www.iabeurope.eu/tcfdocuments/documents/legal/currenttcfpolicyFINAL.pdf"><em>five official purposes</em></a> for which personal data will be used — allowing the user to <em>individually choose</em> which ones to give their consent to — along with the continuously updated list of vendors who endorse some or all of them. In other words, a lot of informational content for the user’s own good, whose importance is nevertheless crucial for the good of all the parties involved.</p><p>All of these ingredients to be wisely mixed up with the by now all-too-common development best practices of UI/UX responsiveness, a lightweight logical flow, and some additional features to monitor the behavior of the software itself.</p><h3><strong>It all boils down to speed and KISS</strong></h3><p>As we’ve now ventured through the waves of a rough sea, here’s the seemingly impossible equation to keep the ship en-route:</p><blockquote>Effectiveness = Ease of use + Completeness + Compliance</blockquote><p>Before developing our in-house solution, we learned some behavioral and technical lessons by using other platforms that were renowned in the market. What we observed is that even though GDPR raised some awareness for users, the tendency is to look at the CMP either as an annoying and engagement-blocking wall or as a scary monster from which to escape.</p><p>A CMP could be perfectly compliant, informationally exhaustive and even user-friendly, and yet fail to be effective. How so? The more a user comes closer to consuming the content they look for on the web — with all the possible setbacks of loading times and external distractions — the more the CMP results as an uninvited guest.</p><p>How to remedy to this lose-lose situation? Simply, the answer is <em>speed</em>.</p><p>The sooner and faster the piece of software loads, the more effective it will be for user-engagement. And here is where the problem becomes evident: many renowned platforms on the market simply are too heavy in terms of <em>file size</em>.</p><p>Sure you may think that constraining the size of the CMP may come hand in hand with the downfall of limiting its features and customizability. This is not the case, and specifically for the purpose of compliance, which enforces a clear and KISS-like logical flow where the crucial information can be served more and more in-depth <em>on demand</em>.</p><h3><strong>Our CMP, tools, and KISS-flow</strong></h3><p>The JS scene by now proposes plenty of tools and frameworks to develop web-applications.</p><p>And as the stress is on the file size and the action flow of the final product, the choice has fallen on a promising library whose main focus is performance: <a href="https://preactjs.com/"><em>PreactJS</em></a>.</p><p>As you may guess, PreactJS appears as (<a href="https://preactjs.com/guide/differences-to-react#whats-missing">but it is not</a> — )a shrunk-down in size version of the famous Facebook library ReactJS. Just like its big brother, it ships the same ES6 component-based architectural style and the same core syntax (props and basic state handling) and templating features (JSX/VDOM). One of the essential differences which explains the extremely reduced size is the absence of some core and heavy-weight ReactJS functionalities: <a href="https://github.com/developit/proptypes">PropTypes</a>, <a href="https://facebook.github.io/react/docs/top-level-api.html#reactchildren">Children</a>, and <a href="https://reactjs.org/docs/events.html">Synthetic Events</a>.</p><p>But at the end of the day, the dev-flow of a CMP simply needs to combine 2 basic parts: the core GDPR-compliant JS functionalities with UI visual elements like text, buttons/toggles, and long lists.</p><p>All of this is organized into 3 views for on-demand information serving:</p><ul><li>A <em>welcome view</em> for overall approval</li><li>A<em> purposes view</em> to toggle consent preferences</li><li>A<em> vendors’ list view </em>for in-depth reading about each vendor’s intent of use of the user’s personal data.</li></ul><p>What about UI styling? It is well-known how CSS styling of HTML components may affect the final file size, but certainly, we wouldn’t want to fail on the goal of user-engagement. Here is where the performance CSS-in-JS postprocessor <a href="https://github.com/streamich/nano-css"><em>nanoCSS</em></a><em> </em>comes in. Its main prerogative? Styles caching and CSS per-component optimization without sacrificing expressivity.</p><p>With this in mind, PreactJS and nanoCSS have proven themselves to be fast and modern development tools in their very nature. But did we make a good choice for the goal of speed and, hence, of file size constraint? You bet. We managed to achieve a currently unmatched final bundle size of 19.8kB (served gzipped) which translates into just a 70kB file size. This while being IAB approved, publically available, and not sacrificing any essential requirement for GDPR compliance.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4cc839d9083" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/marfeel-cmp-a-frontend-development-odyssey-in-the-realm-of-gdpr-d4cc839d9083">Marfeel CMP: A Frontend Development Odyssey in the Realm of GDPR</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conflicts in WordPress and How to Overcome Them]]></title>
            <link>https://medium.com/marfeel-labs/conflicts-in-wordpress-and-how-to-overcome-them-74ba83ae4ce2?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/74ba83ae4ce2</guid>
            <category><![CDATA[wordpress]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[plugins-for-wordpress]]></category>
            <dc:creator><![CDATA[Marfeel Labs]]></dc:creator>
            <pubDate>Thu, 20 Sep 2018 14:16:46 GMT</pubDate>
            <atom:updated>2018-09-20T14:16:45.441Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Written by Eduard | Front End Jedi</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M0IYhNM0S5c-aoTUZpHVlQ.jpeg" /></figure><p>WordPress is a complex ecosystem where a lot of different types of applications coexist with an infinite number of combinations of plugins, themes, and customizations. This is very powerful and gives a developer a lot of freedom to build whatever they need while using all the pieces they might need.</p><p>Yet anyone who has worked in this environment knows that at the same time, it can be a very painful struggle, where, just like in chemistry, a wrong combination of ingredients can be fatal.</p><p>When developing a plugin designed to be used in a large community like WordPress, the potentially chaotic conflicts that are possible has to be on your mind at all times. The goal then is to create a plugin that doesn’t conflict with any of the millions of different permutations of environments that can be installed.</p><p>The purpose of this article is to analyze and find a solution specifically for the conflicts relative to using other plugins as vendors in the plugin you’re developing for WordPress.</p><h3>Example</h3><p>In this example, we start from the idea that we want to create a plugin that loads different templates depending on whether the user agent is mobile or desktop.</p><p>We could implement a class called DeviceDetection that from one user agent can detect if it&#39;s a mobile or not, but in a large community with a lot of contributors, it&#39;s easy to find different options that have already solved that problem, are well tested, and well maintained. So, why reinvent the wheel?</p><p>Therefore, imagine we have a plugin called DEVICE_DETECTION. Using it should be as easy as having the source files in our vendor directory and:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26ac0148e1753a30bc1ff5d8245fe5f4/href">https://medium.com/media/26ac0148e1753a30bc1ff5d8245fe5f4/href</a></iframe><p>A potential problem regarding conflicts here could be that another plugin uses the same require in the same execution. In that case, the class would be loaded twice and our site would crash. Not desired, really.</p><p>But we could avoid that using namespaces:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/faccf63155fec868c9b5bf29eaae3bb7/href">https://medium.com/media/faccf63155fec868c9b5bf29eaae3bb7/href</a></iframe><h3>Example 2</h3><p>The problem now is that maybe some other plugin is using a different version of the DeviceDetection and we are loading their version. Maybe in their version, the is_mobile method had a different name, so we would crash. Better, but we would still be having conflicts in some environments.</p><p>We need to find a solution to isolate ourselves from the rest, even if the class is from another plugin — we need to make the external plugin be only ours.</p><p>The way to do this is to create our own namespace, in that case, we would be the only ones loading that particular class and nobody would conflict with us.</p><p>For example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1c54d094a1b4c55813cd1ed47decea11/href">https://medium.com/media/1c54d094a1b4c55813cd1ed47decea11/href</a></iframe><p>This implies that we need to refactor all files in the DeviceDetection plugin to follow that pattern. We have to do it in a way so that every time they update the module, it&#39;s not a pain in the ass for us to upgrade to the newest version. Forget about one time refactor; this has to be automatic and as transparent as possible.</p><p>Using the composer at build time to execute a script to refactor seems to be the right approach:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b6638979e87744aae6d2041c6890c181/href">https://medium.com/media/b6638979e87744aae6d2041c6890c181/href</a></iframe><p>The script has to replace all usages (uses, namespace declarations, aliases, etc.) to use the new namespace.</p><p>An example of how to give all files of the vendors a prefix to be used only by your plugin should look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0088b1df099eed8b47b589c34965f0df/href">https://medium.com/media/0088b1df099eed8b47b589c34965f0df/href</a></iframe><p>This way, every time we do a build using the composer, after downloading all vendor plugins we’ll automatically refactor them so they are safe to be used anywhere and are conflict-free with different versions of the DeviceDetection plugin.</p><p>With this solution we are able to:</p><ul><li>Avoid version conflicts</li><li>Isolate the vendors from the original</li><li>Easily update vendors</li><li>Perform an automatic refactor.</li></ul><p>Hope this helps other developers make a better, conflict-free WordPress environment.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=74ba83ae4ce2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/conflicts-in-wordpress-and-how-to-overcome-them-74ba83ae4ce2">Conflicts in WordPress and How to Overcome Them</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Set Up Cache Policies for Service Workers to Optimize Performance]]></title>
            <link>https://medium.com/marfeel-labs/set-up-cache-policies-for-service-workers-to-optimize-performance-8fb0a86dc3bc?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/8fb0a86dc3bc</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[service-worker]]></category>
            <dc:creator><![CDATA[Marfeel Labs]]></dc:creator>
            <pubDate>Fri, 07 Sep 2018 13:46:00 GMT</pubDate>
            <atom:updated>2018-09-07T14:35:28.920Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tt2I-IyHwTlOFTH8I5qlQQ.png" /></figure><p><em>Written by Miquel | Frontend Jedi</em></p><p>If you’re reading this I’m going to take the liberty and assume you’re already familiar with Service Workers (SW) and the value they bring to both users and developers.</p><p>If not, here are some links to get you up to speed:</p><ul><li><a href="https://developers.google.com/web/fundamentals/primers/service-workers/">Google’s Introduction to Service Workers</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API#Browser_compatibility">Browser support for service workers</a></li><li><a href="https://w3c.github.io/ServiceWorker/">Service worker specs under development</a></li></ul><p>At Marfeel we were an early adopter for Service Workers; we started using them as soon as they began to be supported to take advantage of the control over network messages, push notifications over the web, and most important, caching.</p><p>Since Marfeel is a platform for publishers, when we decided to take on Service Workers, we started with the caching system first to be able to deliver content faster and offline.</p><h3>Service Workers cache API</h3><p>The SW cache provides an API to use the application cache. It’s like a key-value store which uses request objects as keys and the responses as values. The best thing about it is that devs can choose <em>what</em> to cache and <em>when</em> to consume it or not.</p><p>In our case, we wanted to have control over the resources that we are serving from our origin and cache them according to type.</p><h4>Checking every request</h4><p>To do this, we have to intercept <strong>every and all</strong> requests. So for every request issued from the application, we check if it goes to a Marfeel domain.</p><p>Here’s a simplification of the code we have:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/926f0f8f6ca460eea11d0df76aa45532/href">https://medium.com/media/926f0f8f6ca460eea11d0df76aa45532/href</a></iframe><p>If it’s not a Marfeel resource being requested, the browser proceeds with its normal flow.</p><p>But if<em> it is</em> a Marfeel resource that’s requested, we have different strategies or policies depending on the type of resource. For example:</p><ul><li><strong>Navigation requests</strong>: Since the pages that use our solution are publishers, the navigation requests go to articles and article sections. In this case, we want to be as fresh as possible. Here, the strategy we use is to always get the resource from the network and cache it so that it’s available even if the network isn’t (for example, when the user is offline).</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a01ab23d44b6eb3afd78646edd282ff0/href">https://medium.com/media/a01ab23d44b6eb3afd78646edd282ff0/href</a></iframe><ul><li><strong>For some JS bundles that are not constantly updated</strong>: Cache first. This is quite the opposite. We want to get the content from the cache so the response is immediate, but then “in the background,” issue the request and update the cache so it’s fresh for the next access.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d15a5ab5d2fe54f8d56ab847a7243a37/href">https://medium.com/media/d15a5ab5d2fe54f8d56ab847a7243a37/href</a></iframe><ul><li><strong>Race</strong>: In most cases, we want to try to get the resource from the network, cache at the same time, and return the first one to respond. It should always be the cache response but in case it has not been cached yet or it’s slower, you have the network response.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/144c109768cdbb41175f9341042f9de1/href">https://medium.com/media/144c109768cdbb41175f9341042f9de1/href</a></iframe><ul><li>Also, there are some resources that won’t change over time (some image assets like logos for example) that you can cache as soon as the cache gets initialized, using the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Cache/addAll">addAll() method</a>.</li></ul><p>So with very little code and a lot of debugging and testing, you can have a few cache policies set up.</p><p>Now let’s see what’s changed and if it really is worth it.</p><h3>The results</h3><p>With the previous code we achieved a couple of things:</p><h4>Result #1</h4><p>The first one and the one we aimed to accomplish — an <strong>improvement in performance</strong>.</p><p>Now, the resources we mentioned earlier are being cached, so most of the time, instead of retrieving them from the network, we will get them from the application cache. This will reduce the network time (to 0s) and also the network usage (0 bytes downloaded which on mobile networks should be taken to account).</p><p>Now that the resources are coming faster, the web application’s performance will naturally increase.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/0*y9iHFgCLb4pwz1hW" /><figcaption>Network times without service workers</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/0*_RVxDl9nuUtR9iE3" /><figcaption>Network times with service workers. Notice the difference with the <em>from ServiceWorker</em></figcaption></figure><h4>Result #2</h4><p>The second result is content availability when offline.</p><p>Even when the user has no internet connection, most of the resources that got cached are going to load.</p><p>This is super cool because even with network failures you will be able to use the product. Maybe offline isn’t the ideal scenario but imagine when traveling, using the train, or you simply have a bad signal… some of the resources might fail over normal network conditions and the page would crash or not work. But with this, you won’t even notice.</p><h3>But, we can’t forget that…</h3><ul><li>Even though Service Workers and the right caching policies ultimately improve performance, we <em>are</em> adding overhead. Even if it’s very little, intercepting all the requests, and introducing some logic before getting to the network has some costs.</li><li>All of this will fully work on the 2nd and subsequent loads of the page. On the first load, most of the resources have already been downloaded by the time the Service Workers start.</li><li>The files will be cached, so if you want to deploy a bugfix or something like that, it will take a while unless some cache cleaning policy is implemented.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fb0a86dc3bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/set-up-cache-policies-for-service-workers-to-optimize-performance-8fb0a86dc3bc">Set Up Cache Policies for Service Workers to Optimize Performance</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Guarantee Smooth Animations in JavaScript]]></title>
            <link>https://medium.com/marfeel-labs/how-to-guarantee-smooth-animation-in-javascript-b6de7d694e45?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/b6de7d694e45</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Marfeel Labs]]></dc:creator>
            <pubDate>Fri, 03 Aug 2018 07:44:19 GMT</pubDate>
            <atom:updated>2018-08-03T14:17:58.823Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KRX3osVTzCKWofkdCTsVmw.png" /></figure><p><em>Written by Flore | Full Stack Product Engineer</em></p><p>The browser API has a magical function to help you achieve 60 fps when you animate your HTML: requestAnimationFrame. This is a demonstration of what it does, and why you should prefer it to timer functions.</p><p>requestAnimationFrame takes a callback as an argument. This callback should contain the animating code, with a minimum amount of computation –when you request a frame, you’re ready to use it! In exchange, the browser will trigger the callback right before painting a new frame, <strong>when it works best with the browser’s own routine</strong>, guaranteeing a smooth animation.</p><p>For most browsers, you can get up to 60 callbacks per second. In practice, it means that you can call requestAnimationFrame as many times as you want and the queue of functions will empty at about a rate of 60 callbacks per second.</p><p>The callback is called with one argument: the timestamp, in milliseconds, when it gets called. This allows you, for instance, to know how long your animation has been running for.</p><h3>When to use it</h3><p><strong>Every time</strong> your code is going to perform an animation. The key is to not only call requestAnimationFrame just once, but <strong>every time</strong> you need a repaint. Otherwise, you won’t get many of the benefits from it.</p><p>Here’s a simple example, triggering an animation on click:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fjsfiddle.net%2Fgaranceflore%2FLtks8r64%2Fembed%2Fresult%2F&amp;src=https%3A%2F%2Fjsfiddle.net%2Fgaranceflore%2FLtks8r64%2Fembedded%2F&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/de20cf94019f2ff2a1e75edd543c8ca3/href">https://medium.com/media/de20cf94019f2ff2a1e75edd543c8ca3/href</a></iframe><p>As long as the disc is not positioned on the right side of the box, it keeps moving.</p><p>See how all the frames are nicely regular, and the CPU’s resources are consumed in a regular way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TRm-ZBLwRDQDo9X7chZ-UQ.png" /><figcaption>Browser dev tools view of the frames and CPU usage with requestAnimationFrame</figcaption></figure><p><em>Overall</em>, you can reproduce this behaviour with timing functions, such as setInterval. It will kind of work, but if your app computes things in the middle of it all, you will soon get jank.</p><p>See this second example, using setInterval:</p><iframe src="https://cdn.embedly.com/widgets/media.html?url=https%3A%2F%2Fjsfiddle.net%2Fgaranceflore%2F2khtqnaz%2Fembed%2Fresult%2F&amp;src=https%3A%2F%2Fjsfiddle.net%2Fgaranceflore%2F2khtqnaz%2Fembedded%2F&amp;type=text%2Fhtml&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;schema=jsfiddle" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/1360106726ba307d576d7eb8aaffd011/href">https://medium.com/media/1360106726ba307d576d7eb8aaffd011/href</a></iframe><p>And here are the frames and CPU profile from the dev tools:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/967/1*dycTxTtD-on4uQtdxCnraA.png" /><figcaption>Browser dev tools view of the frames and CPU usage without requestAnimationFrame</figcaption></figure><p>When you launch the example, you probably don’t see any difference. However, you can notice that some frames are missed.</p><p>With a timer function, since we force the animation to run when it is convenient for us rather than for the browser, we’re never safe from surprises like that!</p><h3>Browser Support</h3><p>This function is very well supported, both on mobile and desktop, meaning that you can count on all the evergreen browsers, as well as Opera and IE10.</p><h3>Caveat</h3><p>Your callback will not run if your website is in a background tab, in order to protect the battery life of the user’s phone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6de7d694e45" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/how-to-guarantee-smooth-animation-in-javascript-b6de7d694e45">How to Guarantee Smooth Animations in JavaScript</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging Spring Mvc Tests]]></title>
            <link>https://medium.com/marfeel-labs/debugging-spring-mvc-tests-fb8ce9f8fe8c?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/fb8ce9f8fe8c</guid>
            <category><![CDATA[integration-testing]]></category>
            <category><![CDATA[spring-mvc]]></category>
            <dc:creator><![CDATA[Marfeel Labs]]></dc:creator>
            <pubDate>Fri, 20 Jul 2018 06:59:50 GMT</pubDate>
            <atom:updated>2018-07-20T06:59:49.754Z</atom:updated>
            <content:encoded><![CDATA[<p>– <em>written by</em> <em>Xavi | Java Jedi in the Marfeel Product Team</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*935FHOH6Eh1C62kazDObCg.jpeg" /></figure><p>Sometimes, when implementing an integration test with Spring Mvc, you get an unexpected result. You can spend some time trying to figure out what is going on, but mockMvc comes with a method to help you with this.</p><p>For example, imagine you are testing a secured POST. You provide the credentials using the user() method:</p><pre>mockMvc.perform(<br>        <em>post(ENTRY_POINT </em>+ &quot;test.com/metrics&quot;)<br>                .accept(&quot;application/json&quot;)<br>                .contentType(&quot;application/json&quot;)<br>                .content(serializeJSON(metrics))<br>                .with(<em>user</em>(myUser).authorities(auth)))<br>        .andExpect(<em>status</em>().isOk());</pre><p>Instead of a 200 status code, you get a forbidden error:</p><pre>java.lang.AssertionError: Status<br>Expected :200<br>Actual   :403</pre><p>But you are sure security is well set. So, what is going on?</p><p>One easy way to overcome this is to get more detail about what is happening. The way to do this is adding a print()method:</p><pre>mockMvc.perform(<br>        <em>post(ENTRY_POINT </em>+ &quot;test.com/metrics&quot;)<br>                .accept(&quot;application/json&quot;)<br>                .contentType(&quot;application/json&quot;)<br>                .content(serializeJSON(metrics))<br>                .with(<em>user</em>(myUser).authorities(auth)))<br>        .andDo(MockMvcResultHandlers.print())<br>        .andExpect(<em>status</em>().isOk());</pre><p>This prints all the information regarding the request and response to the console. For instance, the part that interests us in this case is the response:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/731/1*0IyWhB5mYSkboghhL1MrPQ.png" /></figure><p>In this case, it clearly tells you that you are not sending the CSRF token with the request. Easy thing, since you can specify the token in the test request :)</p><pre>mockMvc.perform(<br>        <em>post(ENTRY_POINT </em>+ &quot;test.com/metrics&quot;)<br>                .accept(&quot;application/json&quot;)<br>                .contentType(&quot;application/json&quot;)<br>                .content(serializeJSON(metrics))<br>                .with(<em>csrf</em>())<br>                .with(<em>user</em>(myUser).authorities(auth)))<br>        .andExpect(<em>status</em>().isOk());</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb8ce9f8fe8c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/debugging-spring-mvc-tests-fb8ce9f8fe8c">Debugging Spring Mvc Tests</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Clean Code: A Few Key Rules to Follow]]></title>
            <link>https://medium.com/marfeel-labs/clean-code-a-few-key-rules-to-follow-24eb7a973ff7?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/24eb7a973ff7</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Jose Angel Anguita]]></dc:creator>
            <pubDate>Fri, 22 Jun 2018 14:43:20 GMT</pubDate>
            <atom:updated>2018-07-20T06:58:14.238Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vVXicFhmOOyYASuzkM570w.jpeg" /></figure><p>I don’t want to be hyperbolic, but I’m going to anyway. I think we can separate code into two simple categories: Bad code and clean code.</p><p>One type causes inefficiency, chaos, and wastes time. The other allows developers to jump in and out of projects effectively and with ease to build the cool, exciting things we all want to be a part of.</p><p>This article talks about how to detect bad code, avoid it, and some rules developers should follow so they don’t spend two hours trying to figure out what their colleague was doing with that function.</p><h3>What is bad code and why is it a pain in the a%&amp;?</h3><p>Bad code causes a lot of distractions. On long term projects where many developers work together and perform several changes a day, bad code can creep up on your project real fast. That’s just the law of entropy.</p><p>This causes developers to waste time and energy navigating through functions, classes, files, and pouring over code trying to understand it.</p><p>Bad code is also highly interconnected — it arrives when you realize you have to make a minor functionality change, and then you have to modify a multitude of functions, classes, and files to accommodate that small change.</p><p>As time passes, the efficiency of the team decreases significantly. You could argue that clean code then, is a matter of professional survival.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*oSx-d-MoXuh6MFyGG5kMXg.png" /><figcaption><em>Productivity Vs Time working on bad code</em></figcaption></figure><h3>The merits of clean code</h3><p>Working on a project where developers care about clean code makes it easy to understand its virtues; you can read the code from top to bottom in one go and clearly understand what it does. It makes your code manageable and maintainable in the long term, isolating changes and increasing the efficiency of your team.</p><p>You don’t need to apply all the rules all the time; the idea is to make you — as a developer — get into the habit of thinking critically and rationally about the code you are writing so that before your send your next PR, you review your code and can objectively ask yourself: Is this clean code?</p><p>Here are the some rules that will help you affirmatively answer that question:</p><h3>1 — Naming</h3><p>Everything in code hides a meaning behind its use; it has an intention and you must reflect this meaning using an appropriate name for it.</p><h4>Meaningful names</h4><p>Use meaningful and explanatory names and avoid one or two-letter, ambiguous names. For example, if in a function you return d, the meaning behind that function is hidden. Instead, return isClientSubscribed and avoid the misinformation. If the name includes half-truths or outdated information we are also adding confusion to the concept behind the name.</p><p>In this example we are calculating a state object to return inside a function. You should avoid names like objRet, etc. They don&#39;t add any semantic or meaningful context for that returned object.</p><pre>function createStateObject(data) {<br>    var objRet = {};<br>    <br>    objRet.pageNumber = data.pageNumber;<br>    objRet.pageId = data.currentPage.id();<br>    objRet.postId = data.currentPost.id;</pre><pre>    return objRet;<br>}</pre><p><em>The better idea is to use a name like </em><em>stateObject</em></p><h4>Similar names for similar concepts</h4><p>Use similar names for similar concepts and implement meaningful variations for similar names in favor of autocompletion. Avoid adding noise by using variations like a1, a2, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*b6UT48vqEdUJB1dl-fy0qQ.png" /><figcaption>Example: Meaningful variations for similar names and concepts</figcaption></figure><h4>Abbreviations and encoding</h4><p>Avoid abbreviations or encoding. This forces the reader to learn that encoding and then perform a mental map for that concept every time they have to read, write, or look for it, adding a new layer of complexity to the code.</p><p>In the next example, the developer used an internal abbreviation and encoding to refer to a PushNotifications component in UI.</p><p>If you complete the name pn-layer__example using pushNotifications-layer__example in the name, it will be a lot more meaningful than:</p><pre>.pn-layer__example {<br>  position: relative;<br>  top: 5px;<br>  margin: 5px;<br>}</pre><h4>Classes, methods, and functions</h4><p>Classes are nouns. Methods and functions are verbs.</p><p>Functions must always do something that must be reflected in their name. A name like calculateAmount() is correct if that function just calculates that amount. If it does other calculations or sets an internal status, then we are misinforming the user and introducing side effects that will probably occur when other developers use that function. If this is the case, rename the function to calculateAmountAndSetStatus(). Or better, rewrite it into two separate functions (calculateAmount() and setStatus()) and introduce a better, higher logic using it.</p><h4>Concepts</h4><p>Always use one name per concept. Use get or fetch, controller, or manager... but always use the same name for the same concept.</p><h4>Context</h4><p>If you feel that you can’t find a better name, and it doesn’t reflect the full meaning for your code, you can add extra information inside the context for that name, and you can use that context to add meaningful distinctions to several names.</p><p>In the following example, there are 3 JavaScript classes with the same name, but we are adding context to the name (via their directory) so that the contents are explicit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/504/1*1xkT3xXMtrU6VibNbissDQ.png" /></figure><p>The first and the second one are adserver implementations, the third one is an implementation of Facebook embeds, and the last one is a social provider to get access to the Facebook API.</p><p>If we follow these simple rules, the names we give to elements of our code will be more easily identifiable, pronounceable, and searchable. If we try to find it in our code where the object Cp is used, it’s much more difficult to find than if we try to look for the uses of a class named ColumnPool.</p><p>Also, imagine we need to discuss that class with other developers. Talking about ColumnPool instead of Cp is much easier and more effective.</p><h3>2 — Comments</h3><p>In general, comments are excuses for bad code. If you feel the need to add a comment, you probably need to rethink and rewrite the code.</p><p>While comments can add basic information that the developer needs to understand the code, they can also add misinformation, confusion, and it will not be removed or modified if the code changes.</p><p>They also become read only lines exclusively. If you write a piece of code, you probably won’t be the next one modifying it. Also, the new developer will not modify the comments according to the new changes. This, in time, will be a deprecated comment and will add noise and confusion to the code.</p><p>Therefore, it’s critical that we can identify how to avoid comments, and when we should use them where appropriate.</p><h4>Ineffective comments</h4><p>Ineffective comments are the ones that add misinformation, are incorrect, or outdated. They can also be unnecessary or redundant. Attributions or logs are a good example. Developers should use the other mechanisms at their disposal to provide the necessary context their code needs through comments such as using Git, commenting on the commits, and adding annotations or code blame.</p><pre>class UpperMenu {<br>    constructor(container, openHandlers, header) {<br>        this.upperMenuContainer = container;<br>        this.openHandlers = openHandlers;<br>        this.header = header;<br>        this.isInitialized = false;<br>        this.plugins = [];</pre><pre>        //initialize other properties<br>        this.isOpen = false;</pre><pre>        configureAnimations.call(this);<br>        configureLinks.call(this);<br>        configureAppInstallIcons.call(this);<br>     }</pre><p><em>An example of a redundant comment</em></p><p>The above example is also an example of an outdated comment. It makes no sense to do insert it in the initializations of that constructor function. Looking into the history log, we see that it comes from an old version of the code that another developer didn’t remove. It might have made sense in the past, but is now just outdated and incorrect.</p><h4>Good comments</h4><p>Good comments are the ones that add basic and extra information like time calculations or warnings of the consequences in a temporal push when we are on call solving hot issues in production.</p><p>The next example adds basic, extra information to add readability to our code. It explains that the calculation means 24h in milliseconds.</p><pre>Utils.setCookie(&#39;timeToLive&#39;, &#39;300&#39;, 24 * 60 * 60 *1000); // 24h in millis</pre><p>Tip: In these cases it’s better if we can remove the comment and we declare the value as a const with a descriptive name:</p><pre>const DAY_IN_MILLIS = 24 * 60 * 60 *1000;</pre><pre>Utils.setCookie(&#39;timeToLive&#39;, &#39;300&#39;, DAY_IN_MILLIS);</pre><p>Sometimes we are also dependent on the technology or architecture that, just like our code, has bugs and misbehaves. Because of this we need to coexist with that and perform some kind of hacks and workarounds. In these cases, comments are needed to add that information and context. They should always include a brief explanation and point to a URL for a full explanation.</p><pre>return {<br>    prepareColumnWidth: function prepareColumnWidth(viewNavigator) {<br>        var column = viewNavigator.column,<br>            containerSize = geContainerSize(column);</pre><pre>        // Due to a bug in iOS with position fixed:<br>        // <a href="http://stackoverflow.com/questions/26391059/new-fixed-position-bug-on-ios8">http://stackoverflow.com/questions/26391059/new-fixed-position-bug-on-ios8</a></pre><pre>        column.style.width = containerSize.width + &#39;px&#39;;</pre><pre>        return containerSie;</pre><pre>     }<br>};</pre><h3>3 — Formatting</h3><p>Readability affects maintainability in the long term. Proper formatting must be a team rule by convention. It sets a precedent for future changes and facilitates the quick impact of new developers joining the team and integrating themselves into the project seamlessly.</p><p>Currently, there are numerous ways to ensure and be conscientious of proper formatting. In the past, developers needed to think about it to write better code. Think back to programming on real VT terminals with 80 columns or text editors without really smooth horizontal scrolls. You always tried to write lines with less that 80 letters to avoid that kind of scroll.</p><h4>Modern tools</h4><p>More moderns tools are available to remond you of the rules when you don’t apply them. The lint or linter set of tools analyzes your source code to detect errors and suspicious code.</p><p>Setting a bunch of rules to manage the vertical and horizontal formatting is also a good strategy.</p><h4>Rules</h4><p>Set rules to:</p><ul><li>Account for the horizontal length of the lines</li><li>Maintain the horizontal openness and density to be more readeable</li><li>Add a new indentation per block</li><li>Group by conceptual affinity.</li></ul><p>In general, know the possibilities of your linters and set the necessary rules to add readability and maintainability to your code.</p><h3>4 — Functions</h3><p>Functions should be small. To be small, you must follow the One Thing Rule:</p><blockquote><em>Functions must to do just one thing, and do it well.</em></blockquote><p>If you find that you are doing several things in one function, then rethink and split it into functions with self explanatory names to better explain what it is doing. As always, use descriptive names. Look for a verb to explain what the function is doing.</p><h4>Query — command separation</h4><p>If a function is a query (get, set, is, kind of functions), it cannot be a command (a function that processes or calculates something). If you mix and try to find a proper name to describe the function&#39;s behaviour, then you will write a name with an and or an or in the function&#39;s name. This isn&#39;t exactly considered a best practice.</p><p>Let’s reintroduce the calculateAmountAndSetStatus() example that was presented in the Naming section. This name is a Query(set) and a Command(caluclate); a good example of what to avoid and when to refactor your code to split the function into two separate ones.</p><h4>Side effects</h4><p>In this regard, it’s important that we avoid side effects. Do just one thing, and avoid doing the undocumented things. If another developer uses your code without knowing that you are doing other operations inside it, you will most likely cause side effects including bugs and disfunctionalities.</p><h4>Levels of abstraction</h4><p>Avoid mixing levels of abstractions into one function. If you are operating with your ViewNavigator object, and you are doing Column operations in a higher level, calling methods like Column.left(); or Column.resize(); you can&#39;t access the DOM directly by doing querySelectors to get the status class of an element.</p><p>Encapsulate the details of implementation into a higher level of abstraction, to make functions more readable and to not create dependencies with a low level detail of implementation.</p><p>The next example can be refactored, because we are mixing levels of abstraction calling higher abstraction level functions (like the prepare or reloadImage functions) and accessing the low level details of implementation (classLists or registering events):</p><pre>function imageLayoutChange (image, layout) {<br>    const onImageComplete = function() {<br>        this.classList.remove(&quot;imageLoad&quot;);<br>    };</pre><pre>    image.classList.add(layout);<br>    image.classList.add(&quot;imageLoad&quot;);</pre><pre>    image.prepare();<br>    image.reloadImage();<br>    Util.registerListener(image, &#39;load&#39;, onImageComplete, this);<br>}</pre><p>For example, it can be refactored into this — a more readable code by just renaming and encapsulating it into auto self-explained functions:</p><pre>function imageLayoutChange(image, layout) {<br>    const onImageComplete = function() {<br>        removeLayoutLoadingClass(image, layout);<br>    };</pre><pre>    addImageLayoutLoadingClass(image, layout);<br>    image.prepare();<br>    image.reloadImage();<br>    setImageOnLoadHandler(onImageComplete);<br>}</pre><h4>Parameters</h4><p>Avoid functions with a big list of parameters. More parameters implies that more testing is needed. You can probably create a new data object to group all the parameters.</p><h4>Null and error codes</h4><p>Avoid returning null or error codes in a function, otherwise you will force the user of that function to check the return status before using it. Null and error codes also introduce a higher level of logic to manage error handling and can obscure the main logic of your code.</p><h4>Repetition</h4><p>Don’t repeat yourself. If you detect that you are writing very similar code over and over again, simply refactor your code. I know, you’re probably in a hurry to release your change or new feature into production, but this directly impacts the maintainability of your code in the long run. Every time you need to change that code, you will have to do it twice or even more.</p><p>Here we have common code inside these two methods, one to load and another one to unload media videos from our ViewNavigator Columns:</p><pre>function unloadVideos() {<br>    var videoElements = videoSelector(),<br>        iframe;</pre><pre>if (videoElements.length) {<br>        for (var i=0; i&lt;videoElements.length; i++) {<br>            iframe = videoElements[i].querySelector(&#39;iframe&#39;);</pre><pre>if (iframe) {<br>                iframe.setAttribute(&#39;data-src&#39;, iframe.src);<br>                iframe.src = &#39;about:blank&#39;;<br>            }<br>        }<br>    }<br>}</pre><pre>function loadVideos() {<br>    var videoElements = videoSelector(),<br>        iframe;</pre><pre>if (videoElements.length) {<br>        for (var i=0; i&lt;videoElements.length; i++) {<br>            iframe = videoElements[i].querySelector(&#39;iframe&#39;);</pre><pre>if (iframe) {<br>                iframe.setAttribute(&#39;src&#39;, iframe.dataset.src);<br>                iframe.removeAttribute(&#39;data-src&#39;);<br>            }<br>        }<br>    }<br>}</pre><p>And can be transformed into this, where we have the common code and we inject the method to use to load or unload videos:</p><pre>function manageVideoMedia(method) {<br>    var videoElements = getVideoMediaElements(),<br>        iframe;<br>    <br>    if (videoElements.length) {<br>        for (var i = 0; i &lt; videoElements.length; i++) {<br>            iframe = videoElements[i].querySelector(&#39;iframe&#39;);<br>            iframe &amp;&amp; method(iframe);<br>        }<br>    }<br>}</pre><h3>5 — Classes</h3><p>Classes are a higher level of code organization and just like functions, classes must be small.</p><h4>Vertical Distance Rule</h4><p>Developers should follow the vertical distance rule where methods and functions are grouped by vertical affinity on related concepts. This greatly enhances the readability of your code.</p><h4>Single Responsibility Principle</h4><p>The Single Responsibility Principle is where a class must only abstract one thing, have one responsibility, and just one reason to be changed in the future.</p><p>If a class has more than one responsability, then it will have a higher probability to be changed to add more functionality to that class. This breaks the OCP (Open Close Principle). A class must be opened for extension, but closed by modification. This means that you won’t want to modify the class every time that you extend the functionality.</p><p>Here is a classic example about writers and readers. In the first code example we see a function that reads from the keyboard device, and writes it to an output device, the printer.</p><p>So it’s highly connected with the details of the implementation on how to read and write to that concrete device.</p><pre>void Copy () {<br>    int c;</pre><pre>    while((c = ReadKeyboard()) != EOF) {<br>        WriterPrinter(c);<br>    }<br>}</pre><p>What will happen to this code if we need to write to another output device? At first glance, we can think about writing some code like this:</p><pre>enum OutputDevice {printer, disk};</pre><pre>void Copy(outputDevice dev) {<br>    if(dev == printer) {<br>        WritePrinter(c);</pre><pre>    } else {<br>        WriteDisk(c);<br>    }<br>}</pre><p>Now we are forking the code with the use of an if or a switch. This is not good because we&#39;re probably breaking the One Thing Rule (not in this case, but this is not a clean code).</p><p>To deal with this we can apply the DIP (Dependency Injection Pattern). DIP states that abstraction cannot depend on the details of implementation. The details of implementation must depend on abstractions. Lets see a better approach:</p><pre>class Reader {<br>    public:<br>        virtual int Read() = 0;<br>};</pre><pre>class Writer {<br>    public:<br>        virtual int Write(char) = 0;<br>};</pre><pre>void copy(Reader &amp;r, Writer &amp;w) {<br>    int c;<br>  <br>    while ((c = r.Read()) != EOF) {<br>        w.Write(c);<br>    }<br>}</pre><p>In this example, the Reader class no longer depends on the details of implementation of the current device. This respects the OCP: If we need to add a new device we will only be depending on the contracts of the Reader and Writer classes. So the details of implementation will be dependent on the abstractions. We will implement new Readers and Writers to accomplish that, avoiding the need to modify the original code over and over again.</p><p>Now take a look at your last PR. How clean was it?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24eb7a973ff7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/clean-code-a-few-key-rules-to-follow-24eb7a973ff7">Clean Code: A Few Key Rules to Follow</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are PWAs Just Adding to our Pop Up Problem?]]></title>
            <link>https://medium.com/marfeel-labs/are-pwas-just-adding-to-our-pop-up-problem-c4fd062b5424?source=rss----401dbc33916d---4</link>
            <guid isPermaLink="false">https://medium.com/p/c4fd062b5424</guid>
            <category><![CDATA[mobile-web]]></category>
            <category><![CDATA[pwa]]></category>
            <category><![CDATA[popups]]></category>
            <dc:creator><![CDATA[Xavi Beumala]]></dc:creator>
            <pubDate>Fri, 08 Jun 2018 15:42:14 GMT</pubDate>
            <atom:updated>2018-07-04T09:35:39.682Z</atom:updated>
            <content:encoded><![CDATA[<p>Dear browsers,</p><p>Can we please find a better way to manage all these pop ups I have to close before I can read a word from the page I’m trying to load?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d9F4DWKvmZT3qdCs17pykw.jpeg" /></figure><p>I mean, I get it. Some of them are designed to give me a better browsing experience with “nice” things like the option to translate the page or opting in for push notifications, but even though I haven’t performed an official poll, I think it’s safe to say it’s starting to piss the average user off. This issue isn’t even isolated to specific browsers and operating systems; it affects all of them.</p><p>Let’s take a closer look at all the different pop ups the average reader can now expect to see when they land on page:</p><ol><li>If their OS is configured in English and they visit any non-English site, there’s a pop up offering to translate the page.</li><li>In the European Union, you used to get the mandatory cookie policy. Since GDPR came in with a bang last month, now you get a consent pop up for all traffic in the European Economic Area. That means even if you’re in the US and visit the Guardian for example, you’ll see a consent dialogue.</li><li>Then an interstitial comes up to block rendering and forces me to close another pop up.</li><li>There’s also stickies, which aren’t exactly pop ups but they might as well be.</li><li>Everyone now has a native app so you can expect to see the native app install banner at the top of the screen.</li><li>An opt in for push notifications on the web.</li><li>Then the option to add the site to my home screen.</li><li>And lastly, if navigating on desktop, throw in the Save to Desktop feature for good measure.</li></ol><p>This, all as you land. Before you’ve had a chance to read a word or genuinely interact with the page and register an event that doesn’t involve the close button. By this point, you’ve either forgotten why you first navigated there or maybe even just abandoned the session altogether.</p><p><em>Just an example. App install banner + interstitial + sticky on landing</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*z26Naefyhk8nAhQvqbk-Dg.png" /></figure><p>How did the browser vendors let this happen? And why aren’t they doing more to regulate it?</p><p>Some of these pop ups are a consequence of legal requirements like <a href="https://ec.europa.eu/commission/priorities/justice-and-fundamental-rights/data-protection/2018-reform-eu-data-protection-rules_en">GDPR compliance</a>. Others are APIs that browsers are pushing for like service workers.</p><p>The problem here stems from each browser vendor having different strategies for different APIs. There’s zero cohesion and a complete lack of a shared throttled or metered strategy to promote a clean and organic UX. And that’s how we’ve gotten to the current state we find ourselves in: pop up, after pop up, after pop up.</p><p>This isn’t an original thought. The dev community has also been making a lot of noise around this. Just last week at <a href="https://2018.jsconf.eu/">JSConf EU</a> in Berlin, new capabilities adding to the myriad of noise (like push notification opt ins) was <a href="https://twitter.com/cramforce/status/1003231264239955973?s=12">in the spotlight</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/588/1*GI8ZfMMpsd9nu_zfTPcRZQ.png" /></figure><h3>What needs to be done</h3><p>While there is little reasoning to why the browsers aren’t managing this cascade of pop ups better, there’s a lot more they could, and should be doing.</p><h4>Metered APIs based on priority and engagement</h4><p>The APIs that control these popups need to be throttled by the browser so they are exposed to users based on priority and user fidelity. The dialogues that are required by law should obviously take precedence, followed by a regulated order for the opt-ins for personalized engagement features like push notifications, translation, and adding the site to the home screen or desktop.</p><p>For any traffic in the EU, GDPR compliant consent mechanisms must be shown by law to first-time visitors. All browser vendors should prioritize this pop up and delay the others to relax the reader.</p><p>They should then work together to define a controlled strategy for triggering the other APIs based on a shared threshold of engagement metrics like the number of visits before displaying specific pop ups, time between visits, etc.</p><p>Should the option to download the native app be shown on the first page view right before an interstitial? Probably not.</p><p>Yes, several of these APIs add value to the users that are loyal to a specific brand, but they’re being implemented irresponsibly without any help or direction from browser vendors. For example, Phil Nash makes an excellent point in his blog piece <a href="https://philna.sh/blog/2018/01/08/permissions-on-the-web-suck/"><em>Permissions on the Web Suck</em></a><em>. </em>Nash advocates for more context to nurture push notifications into the ecosystem, but is quick to point out that developers don’t have the opportunity to add this critical context in the <a href="https://developer.mozilla.org/en-US/docs/Web/API/PushManager">PushManager API</a>.</p><p>If not better managed, instead of contributing to the organic evolution of a better user experience, these capabilities that are supposed to add value will simply continue to diminish the elegant UX so many of us are constantly working towards.</p><h4>How developers can help clean up the mess</h4><p>While browser vendors need to provide the appropriate direction so we can be responsible developers, the web dev community needs to uphold and apply best practices when implementing these features that require dialogues.</p><p>Sticking with push notifications on the web for the moment, this has been sadly overlooked.</p><p>In the absence of a logical strategy that respects the reader, we’ve gotten greedy and implemented aggressive tactics that has left users feeling resentful to push notifications and globally disabling them.</p><p><a href="https://developers.google.com/web/fundamentals/push-notifications/permission-ux">Matt Gaunt offers</a> solid patterns and principles to follow for push opt ins, covering all things from offering this feature when it makes sense (like, for example, not on the first page view of the first visit) and the use of a clear settings function for opt outs.</p><p>The browsers clearly have to do their part, but we as developers also have a responsibility to, you know, not make the internet suck.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4fd062b5424" width="1" height="1" alt=""><hr><p><a href="https://medium.com/marfeel-labs/are-pwas-just-adding-to-our-pop-up-problem-c4fd062b5424">Are PWAs Just Adding to our Pop Up Problem?</a> was originally published in <a href="https://medium.com/marfeel-labs">Marfeel Labs</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>