<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kushagra Gour</title>
    <description>The latest articles on DEV Community by Kushagra Gour (@chinchang).</description>
    <link>https://dev.to/chinchang</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F11612%2F379918.jpeg</url>
      <title>DEV Community: Kushagra Gour</title>
      <link>https://dev.to/chinchang</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chinchang"/>
    <language>en</language>
    <item>
      <title>Top paid courses to learn CSS</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Thu, 12 Dec 2024 12:21:07 +0000</pubDate>
      <link>https://dev.to/chinchang/top-paid-courses-to-learn-css-926</link>
      <guid>https://dev.to/chinchang/top-paid-courses-to-learn-css-926</guid>
      <description>&lt;p&gt;If you're looking to learn CSS (or get better at it), there are several excellent paid courses available that cater to different learning styles and levels. Here’s a roundup (in no particular order) of the best options currently on the Internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. &lt;strong&gt;CSS for JavaScript Developers&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Author:&lt;/strong&gt; Josh W. Comeau&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options available:&lt;/strong&gt; Basic, Pro and Ultimate packages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Includes videos, interactive exercises and a Discord community.&lt;/li&gt;
&lt;li&gt;Lifetime access to course materials and updates.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://css-for-js.dev/" rel="noopener noreferrer"&gt;css-for-js.dev&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  2. &lt;strong&gt;CSSBattle's Learn&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Author:&lt;/strong&gt; CSSBattle (Kushagra Gour)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options available:&lt;/strong&gt; Basic &amp;amp; Intermediate courses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Includes interactive levels, hands-on coding, quizzes and interactive playgrounds.&lt;/li&gt;
&lt;li&gt;Play like a game &amp;amp; practice as your learn.&lt;/li&gt;
&lt;li&gt;Lifetime access to course materials and updates.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://cssbattle.dev/learn" rel="noopener noreferrer"&gt;cssbattle.dev/learn&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. &lt;strong&gt;Complete CSS&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Author:&lt;/strong&gt; Piccalilli (Andy Bell)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options available:&lt;/strong&gt; Single course.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Includes course videos and hands-on website-building project.&lt;/li&gt;
&lt;li&gt;Lifetime access to course materials and updates.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://piccalil.li/complete-css" rel="noopener noreferrer"&gt;piccalil.li/complete-css&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. &lt;strong&gt;CSS Demystified&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Author:&lt;/strong&gt; Kevin Powell&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Options available:&lt;/strong&gt; Single course.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Key Features:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;Includes course videos, excercises, code challenges, website-building projects and Discord community.&lt;/li&gt;
&lt;li&gt;Lifetime access to course materials and updates.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://cssdemystified.com/" rel="noopener noreferrer"&gt;cssdemystified.com&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;Check them all out and pick the one that suits you best. Have a great learning journey! 👋🏼&lt;/p&gt;

</description>
      <category>css</category>
      <category>learn</category>
      <category>frontend</category>
    </item>
    <item>
      <title>How to learn &amp; master CSS</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Tue, 01 Aug 2023 16:24:02 +0000</pubDate>
      <link>https://dev.to/chinchang/how-to-learn-master-css-27fk</link>
      <guid>https://dev.to/chinchang/how-to-learn-master-css-27fk</guid>
      <description>&lt;p&gt;Cascading Style Sheets (CSS) is an essential technology used in web development to style and layout web pages. CSS is not like other programming languages because of its unique core concepts and hence learning CSS can be challenging, especially for beginners. In this blog post, I attempt to outline how one can learn and master CSS.&lt;/p&gt;

&lt;p&gt;Learning CSS can be broken down into 2 things: &lt;strong&gt;Learning&lt;/strong&gt; and &lt;strong&gt;Practice&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Learning
&lt;/h2&gt;

&lt;p&gt;You need to learn 2 things in CSS: The core concepts &amp;amp; property-values.&lt;/p&gt;

&lt;h3&gt;
  
  
  Learning Core Concepts
&lt;/h3&gt;

&lt;p&gt;This involves understanding the CSS specific concepts, theoretically. Things like cascade, z-index, box model, selectors etc&lt;/p&gt;

&lt;p&gt;The resources I recommend for this are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://web.dev/learn/css" rel="noopener noreferrer"&gt;web.dev guide&lt;/a&gt; - Super nice articles explaining each of the concepts in CSS. Must read!&lt;/li&gt;
&lt;li&gt;CSSBattles’s &lt;a href="https://cssbattle.dev/learn" rel="noopener noreferrer"&gt;Learn CSS course&lt;/a&gt; - This is a unique interactive game-like experience to understand the concepts of CSS, while not feeling daunting with just reading long articles or videos.&lt;/li&gt;
&lt;li&gt;Josh Comeau's &lt;a href="https://css-for-js.dev/" rel="noopener noreferrer"&gt;CSS for JavaScript developers&lt;/a&gt; course. This man is a wizard in CSS and teaching - an extra-ordinary combination that makes his course excellent for learning CSS.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Learning about Properties and Values
&lt;/h3&gt;

&lt;p&gt;The only resource I recommend here is the MDN docs. To learn properties and values, you should read the MDN docs on various properties. MDN docs provide an in-depth explanation of each property, including its syntax, possible values, interactive examples and browser support. As a routine you can visit the MDN pages of the first 2-3 properties you use daily…its fun!&lt;/p&gt;

&lt;h2&gt;
  
  
  Practice
&lt;/h2&gt;

&lt;p&gt;Once you get a basic knowledge about the core concepts and properties, practice is of utmost important to turn your acquired knowledge into skills. Here are the 2 directions I recommend practicing CSS in:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Page layouts by building pages&lt;/strong&gt; - this is an excellent way to practice what you have learned. It will give you real-world experience in applying CSS concepts and properties to create practical layouts and structures. You can start with building static webpages - grab a design from Dribbble/Behance and turn into HTML &amp;amp; CSS. Then move onto building simple apps like a landing page or a portfolio website.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Properties-values in CSSBattle&lt;/strong&gt; - &lt;a href="https://cssbattle.dev" rel="noopener noreferrer"&gt;CSSBattle&lt;/a&gt; is a game where you play each level by replicating a given image as close as possible in just CSS in minimum number of characters (also called as code-golfing). Now writing minimum CSS may sound very impractical and it is! But you don't need to do code-golfing and can just focus on the matching the image part. Now even that might sound impractical, and yes that is! But surprisingly that gives you a very good practice in CSS properties and also helps develop your creative thinking when you come up with different approaches to replicate each level's image. There are so many levels on CSSBattle that doing them regularly will force you to experiment with each property and explore it in the process! I have personally learnt a lot of properties here like clip-path, radial-gradient and much more.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Disclaimer: I recommend CSSBattle in this post wich I have created. As biased as it may sound, I don't recommend it because I am the creator. It has been my first-hand experience learning a lot on that platform, accompanied by testimonials from a lot of other players.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Final tool
&lt;/h2&gt;

&lt;p&gt;In the end, the thing that will give the final sharpness to your CSS sword is - &lt;a href="https://drafts.csswg.org/" rel="noopener noreferrer"&gt;"The Specifications"&lt;/a&gt;! Specifications are the written documentation on each feature of CSS, by the people who build CSS! It covers every topic in-depth - upto details which then are also used by all the browsers to implement those CSS features. Reading these specifications give you the extra bit of understanding into why every features works the way it does.&lt;/p&gt;

&lt;p&gt;Remember that learning and practicing are not sequential phases, they go hand-in-hand. Never stop learning as CSS language keeps evolving and so should your skills. And with time and practice, you can become a CSS master. Happy CSS-ing! 👋&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>learning</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Learn CSS intuitively - Box Model</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Tue, 21 Mar 2023 12:19:25 +0000</pubDate>
      <link>https://dev.to/chinchang/learn-css-intuitively-box-model-4idl</link>
      <guid>https://dev.to/chinchang/learn-css-intuitively-box-model-4idl</guid>
      <description>&lt;p&gt;Hey there! Welcome to our new series of posts where we try to decipher CSS concepts in an intuitive manner - by relating those concepts to something you already know in the real world so that we can learn CSS like never before! Are you ready for the first concept?? Let's go! 🚀&lt;/p&gt;

&lt;p&gt;First up is - The "CSS Box Model". Everything on a webpage is a box for CSS and every box is like a sandwich 🥪! Just like a sandwich has several layers, each with its own purpose, a box in CSS has several layers that make up its overall appearance and behavior.&lt;/p&gt;

&lt;p&gt;Let's break down the CSS box model into its layers, starting from the inside out:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Content: The content layer is like the yummy &lt;em&gt;filling in a sandwich&lt;/em&gt;. It's the actual content that goes inside the box, such as text, images, or other HTML elements (boxes).&lt;/li&gt;
&lt;li&gt;Padding: The padding layer is like the &lt;em&gt;crust of a sandwich&lt;/em&gt;. It surrounds the filling and separates it  from the wrapping paper of the sandwich. Similarly, padding provides a buffer between the content and the edges of the box. You can add padding to create some breathing space around the content.&lt;/li&gt;
&lt;li&gt;Border: The border layer is like the &lt;em&gt;wrapping paper around a sandwich&lt;/em&gt;. It adds a visible border around the content and padding layers. You can customize the border's thickness, color, and style.&lt;/li&gt;
&lt;li&gt;Margin: Lastly, the margin layer is like the &lt;em&gt;empty space around a sandwich on a plate&lt;/em&gt;. It's the space between the box and any surrounding elements. You can add margin to create some distance between the box and other elements on the page...so that your sandwiches don't just touch each other. 😁&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9W88c6nK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s7tnned30j0bolwfwso.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9W88c6nK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8s7tnned30j0bolwfwso.jpg" alt="A sandwich on plate labelled with different parts of the CSS box model" width="880" height="512"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, you can see that just like how a sandwich has multiple layers that make up its structure and appearance, the CSS box model has multiple layers that does the same for the box. Understanding the box model is very important in controlling the layout of your web pages, so make sure you practice it well enough. You can hop over to &lt;a href="https://cssbattle.dev/play/3"&gt;CSSBattle&lt;/a&gt; and solve some targets to practice your box model learnings.&lt;/p&gt;

&lt;p&gt;How did you like this post? Do you have questions about the CSS box model? What next concept would you want us to give a shot at?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://community.cssbattle.dev"&gt;Let us know on our forum&lt;/a&gt; or on the &lt;a href="https://twitter.com/css_battle/status/1638149293344272384?s=20"&gt;Twitter&lt;/a&gt; post.&lt;/p&gt;

</description>
      <category>css</category>
      <category>frontend</category>
      <category>eli5</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Mocking Web Push notification in Cypress</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Tue, 28 Jun 2022 09:03:24 +0000</pubDate>
      <link>https://dev.to/chinchang/mocking-web-push-notification-in-cypress-35a7</link>
      <guid>https://dev.to/chinchang/mocking-web-push-notification-in-cypress-35a7</guid>
      <description>&lt;p&gt;PushOwl has a JavaScript library that runs on merchant (our customers) websites and handles things like showing UI widgets to request visitor permissions, passing data to the backend, and subscribing the user to the Web Push Service.&lt;/p&gt;

&lt;p&gt;It’s one of the most critical pieces of our system because a slight issue in our script can cause unexpected behavior on our customer websites causing a loss for them. So we take utmost care to test the library rigorously before deploying anything to production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Roadblock
&lt;/h2&gt;

&lt;p&gt;We use Cypress to test our JavaScript library for end-to-end cases - just like how a website visitor would interact with the website and hence our script. As mentioned, one of the most important parts of our library is requesting permission from the user to send them notifications and then subscribe them to the Web Push Service. Permissions on the website are requested by triggering a prompt like so:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jPUmLkIc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iar3ke06ujfvmou8h7st.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jPUmLkIc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iar3ke06ujfvmou8h7st.png" alt="A native prompt asking for permission to show notifications" width="880" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A native prompt asking for permission to show notifications&lt;/p&gt;

&lt;p&gt;Current testing frameworks do not have very great support to test these native permission prompts. You could trigger them in headed mode, but then you can trigger a click on the “Allow” or “Block” buttons programmatically.&lt;/p&gt;

&lt;p&gt;But tests don’t run in the headed mode in the CI environment, they run in headless browsers. In a headless environment, it becomes more difficult because the prompt doesn’t show up at all and just fails!&lt;/p&gt;

&lt;p&gt;There are a few &lt;a href="https://github.com/puppeteer/puppeteer/issues/3461"&gt;open issues in these libraries&lt;/a&gt;, but they still have to see the light of day!&lt;/p&gt;

&lt;p&gt;How do we even test these prompts then? Let’s see how!&lt;/p&gt;

&lt;h2&gt;
  
  
  Going around these permission prompts
&lt;/h2&gt;

&lt;p&gt;Since we can’t interact with these permission prompts, the next best thing we could do was to mock them!&lt;/p&gt;

&lt;p&gt;By mocking, we simply mean converting the following test scenario:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;user lands on the website&lt;/li&gt;
&lt;li&gt;clicks on a button&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sees a permission prompt&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;clicks “Allow” inside the prompt&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;User gets subscribed and an API request is made to the backend&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;to…&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;User lands on the website&lt;/li&gt;
&lt;li&gt;clicks on a button&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;mock browser APIs to behave as if the user clicked “Allow”&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;User gets subscribed and an API request is made to the backend&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s see how we do this in the specific context of Notification permission.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocking browser APIs
&lt;/h2&gt;

&lt;p&gt;Several properties and methods form the complete Web Push Notification subscription flow in the browser. We’ll look into each one individually.&lt;/p&gt;

&lt;h3&gt;
  
  
  Notification.permission
&lt;/h3&gt;

&lt;p&gt;This property on the global &lt;code&gt;Notification&lt;/code&gt; object gives the current status of the website visitor w.r.t. the “Show Notification” permission.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Notification.permission&lt;/code&gt; would have the value as &lt;code&gt;default&lt;/code&gt; in the default case. And it would be &lt;code&gt;granted&lt;/code&gt; or &lt;code&gt;denied&lt;/code&gt; in case you allow or deny it respectively. &lt;/p&gt;

&lt;p&gt;Mocking this property is simple, we use the Cypress’ &lt;code&gt;stub&lt;/code&gt; method like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;Cypress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Commands&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;setPermission&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;permission&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;default&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;permission&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;permission&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And of course, we have this inside a utility function or a Cypress &lt;code&gt;Command&lt;/code&gt; so that we can pass in any permission value and have it set to that.&lt;/p&gt;

&lt;h3&gt;
  
  
  Notification.requestPermission()
&lt;/h3&gt;

&lt;p&gt;This is the method that triggers the permission prompt i.e. we request permission. This is an async function that resolves to a string value - &lt;code&gt;granted&lt;/code&gt; when “Allow” is clicked and &lt;code&gt;denied&lt;/code&gt; otherwise.&lt;/p&gt;

&lt;p&gt;Cypress gives a method to mock async functions. For a successful permission scenario, it would look like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Notification&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;requestPermission&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;resolves&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;granted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  navigator.serviceWorker.register()
&lt;/h3&gt;

&lt;p&gt;According to the Web Push Subscription flow, once we get the &lt;code&gt;granted&lt;/code&gt; permission from the visitor, we need to install a service worker which later handles receiving the push notification and displaying it.&lt;/p&gt;

&lt;p&gt;To install a service worker script, our library would at some point calls &lt;code&gt;navigator.serviceWorker.register()&lt;/code&gt; method and would await for a &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; object on successful resolution of this async method.&lt;/p&gt;

&lt;p&gt;Mocking this method would mean providing a &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; object with the correct keys on it, which looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;activated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;pushManager&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that&lt;/p&gt;

&lt;p&gt;installing a service worker works fine in headless browsers. We’ll even get a &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; object on success. But the reason why we still mock it is the &lt;code&gt;pushManager.subscribe&lt;/code&gt; method in that &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; object above — once the service worker is registered, we call the &lt;code&gt;pushManager.subscriber&lt;/code&gt; method to subscribe the visitor to the remote Web Push notification service and that fails in headless browser environments. Hence, we don’t want our JavaScript library to be calling the actual &lt;code&gt;pushManager.subscribe&lt;/code&gt; method on an actual &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; method 😄&lt;/p&gt;

&lt;p&gt;So let’s mock it too!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;swRegistration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;activated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;pushManager&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;win&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;serviceWorker&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;register&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;resolves&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;swRegistration&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  pushManager.subscribe() - The final step!
&lt;/h3&gt;

&lt;p&gt;In the end, we now also want to stub our own &lt;code&gt;pushManager.subscribe&lt;/code&gt; method in the &lt;code&gt;serviceWorkerRegistration&lt;/code&gt; object we created above. &lt;code&gt;pushManager.subscribe&lt;/code&gt; is also an async function which resolves to a subscription object. So let’s make it do that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// from above&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;swRegistration&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;activated&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;pushManager&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// our mocked subscription object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;subscription&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://fcm.googleapis.com/fcm/send/f.....u0LL&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;expirationTime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;p256dh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;BGBn2Lco....ZUY&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;y8....JWQ&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="nx"&gt;cy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stub&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;swRegistration&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pushManager&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;subscribe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;resolves&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And done!&lt;/p&gt;

&lt;p&gt;Now, all we have to do is set these mocks (which we have as commands) at the right time and trick our JavaScript library into believing that the user is subscribing, or not!&lt;/p&gt;

&lt;p&gt;In the end, I’ll leave you with a nice quote:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Testing is an infinite process of comparing the invisible to the ambiguous in order to avoid the unthinkable happening to the anonymous.”&lt;strong&gt;— &lt;a href="https://twitter.com/jamesmarcusbach"&gt;James Bach&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Keep testing! Until next time!&lt;/p&gt;

</description>
      <category>cypress</category>
      <category>testing</category>
      <category>automation</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Learn Frontend, the right way</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Wed, 06 Nov 2019 09:42:01 +0000</pubDate>
      <link>https://dev.to/chinchang/learn-frontend-the-right-way-lbn</link>
      <guid>https://dev.to/chinchang/learn-frontend-the-right-way-lbn</guid>
      <description>&lt;p&gt;Hello devs!&lt;/p&gt;

&lt;p&gt;Do you want to learn Frontend development, the right way?&lt;/p&gt;

&lt;p&gt;I present to you, the first-ever tweet-sized course -&amp;gt; &lt;a href="https://twitter.com/i/moments/1187229313579438080"&gt;https://twitter.com/i/moments/1187229313579438080&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This course is an attempt to share my &lt;a href="https://kushagra.dev"&gt;8+ years of learnings&lt;/a&gt; in the field of Frontend. You'll learn to create performant and accessible web pages with a solid understanding of which web technology to use for which purpose. The course is completely available on Twitter, in the form of tweets!&lt;/p&gt;

&lt;p&gt;2 chapters are already out. So head out to &lt;a href="https://twitter.com/i/moments/1187229313579438080"&gt;https://twitter.com/i/moments/1187229313579438080&lt;/a&gt; and follow along with the chapters.&lt;/p&gt;

&lt;p&gt;Happy learning! 😃&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>html</category>
      <category>css</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Terminal commands for daily use</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Fri, 11 Oct 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/chinchang/terminal-commands-for-daily-use-1hag</link>
      <guid>https://dev.to/chinchang/terminal-commands-for-daily-use-1hag</guid>
      <description>&lt;p&gt;This post is a compilation of the most used commands I use in my terminal daily. A reason to share this compilation is to give a quick introduction to how a few very common regular tasks can be done through commands in a terminal. I find running commands in the terminal a lot faster than otherwise doing through the GUI and hence makes me more productive. If you feel you are better without them, that is completely fine too. But I suggest everyone should try them to see what works best for you.&lt;/p&gt;

&lt;p&gt;There are 2 bonus tips at the end of this post to give you that extra productivity boost. Do read till the end.&lt;/p&gt;

&lt;h2&gt;
  
  
  List all files with human-readable filesizes
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ls -lah some/folder/path
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;l&lt;/code&gt; - lists the files &lt;strong&gt;l&lt;/strong&gt; ong format.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a&lt;/code&gt; - lists &lt;strong&gt;a&lt;/strong&gt; ll the files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;h&lt;/code&gt; - lists filesize in more &lt;strong&gt;h&lt;/strong&gt; uman-readable way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tip: you can list files of the current folder with &lt;code&gt;ls .&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Switch directory
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd some/folder/path
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a new file
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch fileName.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Creates an empty file with the name &lt;code&gt;fileName.js&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create a new folder
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mkdir new-folder-name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Copy a file
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cp copyFrom.js copyTo.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Rename a file
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mv oldFile.js newFile.js
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Open a file in Visual Studio Code (VSCode)
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;code fileName.css
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is really useful. If you are not aware, VSCode can be added as a shell command too. Here is [how to add VSCode as shell command][vscode-command].&lt;/p&gt;

&lt;h2&gt;
  
  
  Git commands
&lt;/h2&gt;

&lt;p&gt;I am going to club these into one section.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;git status&lt;/code&gt; - Check the status of the repository in the current directory&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git checkout master&lt;/code&gt; - Switch to &lt;code&gt;master&lt;/code&gt; branch&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git pull --rebase origin &amp;lt;branch_name&amp;gt;&lt;/code&gt; - Pull remote changes from a branch called &lt;code&gt;branch_name&lt;/code&gt; and apply my unpushed changes over those pulled changes&lt;/li&gt;
&lt;li&gt;`git commit -m "my message here" - Commit changes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;git push origin &amp;lt;branch_name&amp;gt;&lt;/code&gt; - Push changes of branch &lt;code&gt;branch_name&lt;/code&gt; to remote&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Open any file (Max OSX only)
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;&lt;br&gt;
open /some/path/filename.ext&lt;br&gt;
&lt;/code&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This basically works like double-clicking a file in the GUI file explorer. It opens the file in the default program set for that type of file. Super useful!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;open&lt;/code&gt; is a Mac OSX command, but I am sure every OS has something similar.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus Tips
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Quickly accessing your terminal
&lt;/h3&gt;

&lt;p&gt;When you start using your terminal for little quick things like mentioned above, it becomes all the more necessary that you are able to do them fast enough without any overhead. And so it makes sense to do some tweaks to make your terminal accessible as quickly as possible.&lt;/p&gt;

&lt;p&gt;For that, you can do 2 things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;First, set your terminal to show as an overlay on the screen i.e. on top of whatever window you have open in front of you. In case you have spaces (also referred as workspaces) enabled on your machine, showing as overlay prevents unnecessary context switch in changing spaces (because you'll switch to whatever space the terminal window is in) and also removes the time delay it would take to switch spaces. Overlay terminal shows instantly.&lt;/li&gt;
&lt;li&gt;Next, set a hotkey on your terminal. That enables you to show up your terminal with a quick keyboard shortcut.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Most terminals (I have tested on Hyper and iTerm) let you do the above things natively or through some plugin.&lt;/p&gt;

&lt;h3&gt;
  
  
  Aliases
&lt;/h3&gt;

&lt;p&gt;With time, you'll realise that you use a few commands more frequently than others. For these commands, you can set &lt;a href="http://www.peachpit.com/articles/article.aspx?p=31442&amp;amp;seqNum=5"&gt;aliases&lt;/a&gt;. Aliases are short names given to commands so that you don't have to type the complete command again and again. Whatever shell you are using, they allow setting aliases. You can find how to set aliases in your shell by searching "How to set aliases in &amp;lt;your_shell_name&amp;gt;". By default, most operating systems give your &lt;code&gt;bash&lt;/code&gt; shell.&lt;/p&gt;

&lt;p&gt;Also, here is a good article on &lt;a href="https://www.thegeekdiary.com/examples-of-creating-command-alias-in-different-shells/"&gt;setting aliases in few different shells&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Hope this post proves useful to you and give you some extra productivity boost! Ciao!&lt;/p&gt;




&lt;p&gt;I am starting a first-ever "Tweet-Course" on Frontend development. Yes! Learn frontend with tweet-size chapters spanning from HTML to CSS to JavaScript. Follow the &lt;a href="https://twitter.com/learn__frontend"&gt;@learn__frontend&lt;/a&gt; account to take this free course.&lt;/p&gt;

</description>
      <category>terminal</category>
      <category>cli</category>
      <category>productivity</category>
      <category>shell</category>
    </item>
    <item>
      <title>Strong vs Em</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Sun, 25 Aug 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/chinchang/strong-vs-em-5cb2</link>
      <guid>https://dev.to/chinchang/strong-vs-em-5cb2</guid>
      <description>&lt;p&gt;&lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; are two of the most basic tags that we learn when we start learning HTML. I am sure you must have used both these tags multiple times. I have too. But somewhere at the back of my mind I always had that slight confusion about which cases each should be used. In fact about which places one tag shouldn't be used. So I finally decided to look up the specifications to clear that doubt once and for all. And I must admit, the specification does a great job at explaining the purpose of each.&lt;/p&gt;

&lt;p&gt;If you also face that slight confusion about using &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; tags, you are at the right place. This article tries to re-express the learnings I got by reading the &lt;cite&gt;W3C specification&lt;/cite&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;If it's just visual importance, you want &lt;code&gt;strong&lt;/code&gt;. If it alters the sentence meaning, use &lt;code&gt;em&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; tag
&lt;/h2&gt;

&lt;p&gt;Firstly, to quote the &lt;cite&gt;&lt;a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-strong-element" rel="noopener noreferrer"&gt;HTML specification&lt;/a&gt;&lt;/cite&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The strong element represents strong importance, seriousness, or urgency for its contents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's try to understand those 3 use cases.&lt;/p&gt;

&lt;h3&gt;
  
  
  Importance
&lt;/h3&gt;

&lt;p&gt;Importance can be thought of like "hierarchy". For example, say you are describing certain items in different paragraphs. You will probably start the paragraph by putting the item name in &lt;code&gt;strong&lt;/code&gt; tags, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;
  &amp;lt;strong&amp;gt;Item X&amp;lt;/strong&amp;gt;: This paragraph is all about describing Item X, it's
  properties and behaviour.
&amp;lt;/p&amp;gt;

&amp;lt;p&amp;gt;
  &amp;lt;strong&amp;gt;Item Y&amp;lt;/strong&amp;gt;: This paragraph is all about describing Item Y, it's
  properties and behaviour.
&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They are acting similar to headings, visually. I compare importance with hierarchy because if someone needs to quickly scan all such items described in the paragraphs, they can just glance at the &lt;code&gt;strong&lt;/code&gt; texts which also appear bold (and hence seemingly higher up the hierarchy).&lt;/p&gt;

&lt;h3&gt;
  
  
  Seriousness
&lt;/h3&gt;

&lt;p&gt;A classic example of this is when you need to show a warning or error. You could simply show a sentence describing the whole warning but there could be a chance that the user ignores reading the whole text, and thus the warning. To make it more evident that the particular text is conveying a warning, we can wrap it in &lt;code&gt;strong&lt;/code&gt; tags. Again, the bold appearance of the &lt;code&gt;strong&lt;/code&gt; tag helps us convey that this is not just another text. It's something serious and needs to be seen.&lt;/p&gt;

&lt;p&gt;A simple example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;strong&amp;gt;Warning: You data will lost in 35 seconds&amp;lt;/strong&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which renders as:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Warning: You data will be lost in 35 seconds&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Urgency
&lt;/h3&gt;

&lt;p&gt;This use case is something I have encountered quite a lot, especially while writing emails. Say you are writing a long paragraph and there are certain things that you want the reader to read first and foremost. Those things can be wrapped in &lt;code&gt;strong&lt;/code&gt; tags.&lt;/p&gt;

&lt;p&gt;Again, the whole premise is that the person reading your long text doesn't have the time to read all the text and even if they do, there might be certain important pieces of text that are intended to be read first and act urgently. The &lt;code&gt;strong&lt;/code&gt; tag helps us achieve that.&lt;/p&gt;

&lt;p&gt;I know all the 3 use cases seem similar and overlapping each other. That is true. But overall they do help to construct a good set of intentions where you would use the &lt;code&gt;strong&lt;/code&gt; tag.&lt;/p&gt;

&lt;h2&gt;
  
  
  The &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; tag
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;em&lt;/code&gt; tag reads as &lt;code&gt;emphasis&lt;/code&gt; but it certainly isn't just that. In fact, it's that word &lt;em&gt;emphasis&lt;/em&gt; that has confused a lot of us in thinking that it is similar to the &lt;code&gt;strong&lt;/code&gt; tag, which is also used to emphasize the importance of something. And it is not!&lt;/p&gt;

&lt;p&gt;Again, to quote the &lt;cite&gt;&lt;a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-em-element" rel="noopener noreferrer"&gt;HTML specification&lt;/a&gt;&lt;/cite&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The em element represents stress emphasis of its contents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Stress emphasis&lt;/strong&gt; is the important thing to note here. It actually has to do with how you speak a particular piece of text.&lt;br&gt;&lt;br&gt;
Let me explain the gist of &lt;code&gt;em&lt;/code&gt; tag with a gif:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F31P5RGyIVBhMMfw0F7%2F200w.webp" class="article-body-image-wrapper"&gt;&lt;img id="gif" alt='A person making air quotes while text shows on then screen: Get the "Laundry" (with quotes around the word - "laundry")' src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F31P5RGyIVBhMMfw0F7%2F200w.webp"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://giphy.com/" rel="noopener noreferrer"&gt;via GIPHY&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am sure you have seen people doing this quote gesture while speaking a particular word or phrase in a long sentence. Imagine they hadn't done that gesture while speaking that word/phrase. Would you have got the same meaning out of that speaker? No. Because the specific stress that the speaker put on that particular part of the sentence, changed their intended meaning.&lt;/p&gt;

&lt;p&gt;This is exactly what the &lt;code&gt;em&lt;/code&gt; tag helps you do while writing. You can wrap certain parts of sentences to simulate the same stress as you would while speaking.&lt;/p&gt;

&lt;p&gt;To make it more clear, I would like to show you the exact example from the &lt;cite&gt;HTML specification&lt;/cite&gt; because I think it does the job perfectly in explaining what &lt;code&gt;em&lt;/code&gt; tag does.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;These examples show how changing the stress emphasis changes the meaning. First, a general statement of fact, with no stress:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;Cats are cute animals.&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By emphasizing the first word, the statement implies that the kind of animal under discussion is in question (maybe someone is asserting that dogs are cute):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;em&amp;gt;Cats&amp;lt;/em&amp;gt; are cute animals.&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Moving the stress to the verb, one highlights that the truth of the entire sentence is in question (maybe someone is saying cats are not cute):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;Cats &amp;lt;em&amp;gt;are&amp;lt;/em&amp;gt; cute animals.&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By moving it to the adjective, the exact nature of the cats is reasserted (maybe someone suggested cats were mean animals):&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;Cats are &amp;lt;em&amp;gt;cute&amp;lt;/em&amp;gt; animals.&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Similarly, if someone asserted that cats were vegetables, someone correcting this might emphasize the last word:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;Cats are cute &amp;lt;em&amp;gt;animals&amp;lt;/em&amp;gt;.&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;By emphasizing the entire sentence, it becomes clear that the speaker is fighting hard to get the point across. This kind of stress emphasis also typically affects the punctuation, hence the exclamation mark here.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;em&amp;gt;Cats are cute animals!&amp;lt;/em&amp;gt;&amp;lt;/p&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Anger mixed with emphasizing the cuteness could lead to markup such as:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Cats are cute animals!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hope these examples make it all clear.&lt;/p&gt;

&lt;h2&gt;
  
  
  Screen reader accessibility
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;strong&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;em&amp;gt;&lt;/code&gt; are not just meant to convey semantics visually, but they are also supposed to convey the same meaning to screen reader users too, ideally through a change of voice.&lt;/p&gt;

&lt;p&gt;From what I could test, VoiceOver doesn't seem to differentiate normal text from the emphasized text. Also, there seems to be no recent studies on the Web for other screen readers like JAWS and NVDA. Hence, I am not covering this topic in much details. I would appreciate if someone can share studies on this matter, which I can update here.&lt;/p&gt;

&lt;p&gt;Nevertheless, screen readers are continuously improving and our correct use of the tags will only help users eventually.&lt;/p&gt;

&lt;p&gt;Also, it's worth noting that accessibility isn't always about screen readers. The visual difference that comes with &lt;code&gt;strong&lt;/code&gt;/&lt;code&gt;em&lt;/code&gt; tag is great for increasing reading comprehension and helping with cognitive disabilities like dyslexia.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;Next time you get confused which tag to use out of &lt;code&gt;strong&lt;/code&gt; and &lt;code&gt;em&lt;/code&gt;, think about this: What's your intention to change the visual appearance of a certain word or phrase? Is it just visual importance of does your stress actually help in communicating better by changing the meaning of the sentence (like you would have stressed while speaking)?&lt;/p&gt;

&lt;p&gt;If it's just visual importance, you want &lt;code&gt;strong&lt;/code&gt;. If it alters the sentence meaning, use &lt;code&gt;em&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What about &lt;code&gt;b&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; tags?
&lt;/h2&gt;

&lt;p&gt;There is also a common confusion while choosing between &lt;code&gt;strong&lt;/code&gt;/&lt;code&gt;b&lt;/code&gt; and &lt;code&gt;em&lt;/code&gt;/&lt;code&gt;i&lt;/code&gt;. Visually they look exactly the same as their counterparts. Then what's the difference?&lt;/p&gt;

&lt;p&gt;The difference lies in semantics. &lt;code&gt;strong&lt;/code&gt; and &lt;code&gt;em&lt;/code&gt; bring in some additional context or meaning wherever used. On the other hand, &lt;code&gt;b&lt;/code&gt; and &lt;code&gt;i&lt;/code&gt; are just for styling and visually differentiating some part of the sentence from the rest. You can consider &lt;code&gt;b&lt;/code&gt; tag the same as a &lt;code&gt;span&lt;/code&gt; with a CSS of &lt;code&gt;font-weight: bold&lt;/code&gt; applied on it. Similarly, &lt;code&gt;i&lt;/code&gt; can be thought of as a &lt;code&gt;span&lt;/code&gt; with CSS of &lt;code&gt;font-style: italics&lt;/code&gt; applied on it.&lt;/p&gt;

&lt;p&gt;So if you want to communicate importance, urgency or seriousness, use &lt;code&gt;strong&lt;/code&gt;. If you just need to draw attention without any importance, use &lt;code&gt;b&lt;/code&gt; or rather just use CSS &lt;code&gt;font-weight&lt;/code&gt;. Similarly, if you want put stress on something, use &lt;code&gt;em&lt;/code&gt;. If it's just about highlighting a different type of text, such as a word in another language, then use &lt;code&gt;&amp;lt;i&amp;gt;&lt;/code&gt; or just CSS &lt;code&gt;font-style&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-b-element" rel="noopener noreferrer"&gt;Read more about &lt;code&gt;b&lt;/code&gt; tag&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-i-element" rel="noopener noreferrer"&gt;Read more about &lt;code&gt;i&lt;/code&gt; tag&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is all for this post. Hope this helps understand these common tags better.&lt;/p&gt;




&lt;p&gt;Special thanks to &lt;a href="https://twitter.com/jitendravyas" rel="noopener noreferrer"&gt;Jitendra Vyas&lt;/a&gt;, &lt;a href="https://twitter.com/stommepoes" rel="noopener noreferrer"&gt;@stommepoes&lt;/a&gt;, and the lovely members of &lt;a href="https://web-a11y.slack.com/" rel="noopener noreferrer"&gt;Slack Web Accessibility group&lt;/a&gt; for reviewing this post.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>html</category>
    </item>
    <item>
      <title>Case Study: Accessibility Report for Managers - Part 1</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Thu, 08 Aug 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/chinchang/case-study-accessibility-for-managers-part-1-862</link>
      <guid>https://dev.to/chinchang/case-study-accessibility-for-managers-part-1-862</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a case-study of why and how I created my recent side-project - &lt;a href="https://a11yformanagers.now.sh/" rel="noopener noreferrer"&gt;Accessibility Report for Managers&lt;/a&gt;. Part 1 talks about the idea behind it and how the Frontend was created.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Accessibility is a very important aspect of any product. If your product isn’t accessible to every possible user, then you are simply losing out on potential users. Over the past few years, I have grown to care more and more about accessibility in every work I do, not just web development, but everything. With that also comes the disappointment to see all these websites out that that break even the basic accessibility rules.&lt;/p&gt;

&lt;p&gt;Lack of knowledge is certainly the reason for poor accessibility in websites. But it isn’t always just the lack of knowledge of developers. I feel there are times when developers do want to take time out to improve the accessibility in their work as they slowly learn new and new things, but they are not always given the freedom to do so. Again, it’s the lack of knowledge and empathy, but in a different set of people who manage these developers. That is why Accessibility, and for that matter, any part of a website, is not just a developer’s job. It needs to be a company value that starts from the early stage of idea conceptualisation, to design, development, product management, marketing, and beyond.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Idea behind “Accessibility Report for Managers”
&lt;/h2&gt;

&lt;p&gt;The most common argument we get to hear from people who are tried to convinced about focusing on Accessibility is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Hey, do we really have those kinds of users? Has anyone ever complained about our website not being accessible?&lt;br&gt;
-- A Manager&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This gave me an idea - why not make an app that gives these people what they want - real feedback from actual users. But then I thought, the primary aim here is “real feedback”, not “actual users” 😉 This led to the whole concept for “Accessibility Report For Managers” - website where you can enter any website URL and generate a report full of dummy feedbacks about actual Accessibility issues on that website, by dummy users 🙂 You take this report to your manager who was asking for real customer feedback all this time, and voila!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt; : The idea here is not at all to diminish the importance of actual accessibility testing and feedback submitted by real users. That is at most important. This app is just a fun attempt to bring a different perspective to look at real accessibility issues.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Real value
&lt;/h2&gt;

&lt;p&gt;Okay, fun part aside. &lt;strong&gt;Accessibility Report for Managers&lt;/strong&gt; isn’t just a funny impractical website to generate these fake feedback. I realised it serves a more practical purpose. This app basically gives you a very different, a customer oriented, view of the Accessibility issues present on your website. Compare this to reading a story and actually seeing/hearing the same story in a movie. Similarly, a textual list of issues generated from a linter would not create the same amount of empathy inside the reader that probably a tweet from a disappointed user showing a screenshot of something broken on the website would do.&lt;/p&gt;

&lt;p&gt;For example, compare these two:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linter&lt;/strong&gt; : Color contrast not sufficient. It should be at least 4.5:1.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;User Feedback&lt;/strong&gt; : Hey web admin, I was browsing through your website to get some work done but at some places, it’s really hard for me to read the text, probably due to poor colour contrast.&lt;/p&gt;

&lt;p&gt;I hope you can see the huge difference between the two. I feel the latter gives a very understandable view of the same issue.&lt;/p&gt;
&lt;h2&gt;
  
  
  TL;DR: Creating the App
&lt;/h2&gt;

&lt;p&gt;This app, though seemingly small, has quite a few components behind the scenes. And the best part, as a frontend developer I could write it all in JavaScript and run without actually setting up or managing a server. These things really excite me and this article series is an attempt to share the whole process of creating such an app with all the latest tech out there. Let’s begin with the tech stack used in the app.&lt;/p&gt;

&lt;p&gt;Note: The app is &lt;a href="https://github.com/chinchang/a11y-for-managers/" rel="noopener noreferrer"&gt;open-source on Github&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Component 1 - The Frontend
&lt;/h3&gt;

&lt;p&gt;I chose &lt;a href="https://preactjs.com/" rel="noopener noreferrer"&gt;Preact&lt;/a&gt; to write this app’s frontend. Preact is an extremely lightweight (just 3KB gzipped) alternative to React with almost the same API. It’s perfect for a scenario where you have such a small app and you don’t wanna overload it with some framework’s footprint.&lt;br&gt;&lt;br&gt;
I used Preact’s &lt;code&gt;preact-cli&lt;/code&gt; which does a basic scaffolding for a Preact Progressive Web App. There is no other dependency on Frontend apart from Preact.&lt;/p&gt;

&lt;p&gt;The CSS is written the old-fashioned way - a single CSS file.&lt;/p&gt;
&lt;h3&gt;
  
  
  Component 2 - The Backend
&lt;/h3&gt;

&lt;p&gt;The backend is basically a set of serverless functions which creates 2 endpoints for the frontend. Again, they are all written in JavaScript (NodeJS).&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;There is one API endpoint to get the actual issues on a given page which uses the &lt;a href="https://github.com/pa11y/pa11y" rel="noopener noreferrer"&gt;pa11y&lt;/a&gt; package to extract out all the issues.&lt;/li&gt;
&lt;li&gt;The second API endpoint is to get the screenshot of affected areas. This is done using &lt;a href="https://pptr.dev/" rel="noopener noreferrer"&gt;Puppeteer&lt;/a&gt; to get screenshot of specific elements on the page.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  Component 3 - Deployment
&lt;/h3&gt;

&lt;p&gt;Both, the frontend and the backend, are hosted on Zeit Now. It simply involves writing the deployment configuration for your components and everything gets deployed with a single command without managing any server!&lt;/p&gt;
&lt;h2&gt;
  
  
  The Frontend
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; : Till we get to the Backend, assume that we have a backend API. We can send any URL to the API and it returns us a list of Accessibility issues.&lt;/p&gt;
&lt;h3&gt;
  
  
  The framework
&lt;/h3&gt;

&lt;p&gt;I love React. But if the project I am working on is not too demanding in terms of features and I am the only one working on it, I prefer to use &lt;a href="https://preactjs.com/" rel="noopener noreferrer"&gt;Preact&lt;/a&gt; - which is a 3KB alternative to React. It almost feels like I am shipping a vanilla JS app while getting the same ease as with React.&lt;/p&gt;

&lt;p&gt;Preact also has a CLI that scaffolds a basic progressive app.&lt;/p&gt;
&lt;h3&gt;
  
  
  Creating fake tweets - Content
&lt;/h3&gt;

&lt;p&gt;As I mentioned, our API gives us a list of Accessibility issues (found through &lt;a href="https://github.com/pa11y/pa11y" rel="noopener noreferrer"&gt;pa11y&lt;/a&gt;). First of all, we need to turn these into tweets. Each issue in the list is of the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;code&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WCAG2AA.Principle2.Guideline2_4.2_4_1.H64.1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Iframe element requires a non-empty title attribute that identifies the frame.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#77c8c1c1-74e9-4d61-be2e-c1e39ffe02a0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;code&lt;/code&gt; is a unique identifier for a particular Accessibility guideline that wasn’t followed, explained in brief in the &lt;code&gt;message&lt;/code&gt; value. The main gist of this app is to turn the technical guideline into seemingly real feedback from a real user. That is why I need to convert that into a tweet. And the same tweet always for a particular issue type would look unreal and boring. So I maintain 3-4 different tweets for each issue type and pick one out randomly. Like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;supportedRules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;INSUFFICIENT_CONTRAST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WCAG2AA.Principle1.Guideline1_4.1_4_3.G18.Fail&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;MISSING_LABEL_ON_FORM_CONTROL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WCAG2AA.Principle1.Guideline1_3.1_3_1.F68&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;generateFeedback&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;issue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nx"&gt;supportedRules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;MISSING_LABEL_ON_FORM_CONTROL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="s2"&gt;`Dear Web Developer, I cannot see and browse the web using a screen reader. And websites like &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; on which you don't label your form elements are completely unusable to people like me. #fixtheweb #a11y`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;`Oh God! It's a disaster browsing websites where the developer simply didn't care to put a label on form controls!! Encountered one such site -&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; #accessibility.`&lt;/span&gt;
        &lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="nx"&gt;supportedRules&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;INSUFFICIENT_CONTRAST&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
          &lt;span class="s2"&gt;`Hello! I was browsing through your website &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; and facing issues with reading few texts. I guess it could get a lil' better for people like me if the text color had some more contrast with the background.`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="s2"&gt;`It's such a difficult task to read websites these days. Eg. Missing text contrast here -&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; Someone please fix the web. #accessibility`&lt;/span&gt;
        &lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
      &lt;span class="p"&gt;};&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What's happening here is, I have made enums for the supported Accessibility guideline codes to make it more clear while referencing them. Then there is the &lt;code&gt;generateFeedback&lt;/code&gt; function which does a &lt;code&gt;switch&lt;/code&gt; on the accessibility issue &lt;code&gt;code&lt;/code&gt; and returns a random feedback from a list of feedbacks corresponding to that issue.&lt;/p&gt;

&lt;p&gt;One more thing to note here is that I pass the URL of the website, whose report is being generated, to the &lt;code&gt;generateFeedback&lt;/code&gt; function. This passed argument gets used in the &lt;code&gt;${url}&lt;/code&gt; placeholder within the feedback strings, which are actually &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals" rel="noopener noreferrer"&gt;template literals&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating fake tweets - Fake users
&lt;/h3&gt;

&lt;p&gt;This one is interesting! Next, we need some fake users to show within our feedback tweets. I searched a lot for services which would give me random user data and finally settled on &lt;a href="https://randomuser.me/" rel="noopener noreferrer"&gt;https://randomuser.me&lt;/a&gt;. It’s free, fast and gave me the data I wanted (eg. name, photo etc). It has an API with all sorts of options, but the one that is of our interest here is the &lt;code&gt;results&lt;/code&gt; option. You can pass a count in &lt;code&gt;results&lt;/code&gt; parameter and the API will return that number of fake users to you. Sweet right!&lt;/p&gt;

&lt;p&gt;So the whole report generation process till now is as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I get a list of issues from the API&lt;/li&gt;
&lt;li&gt;The issue list is converted into fake feedback tweets (only the issues which are supported)&lt;/li&gt;
&lt;li&gt;As per the number of feedbacks we generate, we fetch those number of fake user from &lt;a href="https://randomuser.me/" rel="noopener noreferrer"&gt;https://randomuser.me&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Creating fake tweets - Twitter handles
&lt;/h3&gt;

&lt;p&gt;To complete our fake feedback tweet, we need to show the twitter handles (username) of our fake users. Now we could just create random strings out of numbers and alphabets, but that would again look unreal. And what's the fun in making unreal stuff! So here is what I do instead:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;For each user, we have the user’s full name.&lt;/li&gt;
&lt;li&gt;I extract some part of the user’s first name ( &lt;strong&gt;F&lt;/strong&gt; ) and some part of their last name ( &lt;strong&gt;L&lt;/strong&gt; ).&lt;/li&gt;
&lt;li&gt;Then with a 50% probability, I concat &lt;strong&gt;F&lt;/strong&gt; and &lt;strong&gt;L&lt;/strong&gt; with an underscore. The other 50% times, I concat them straightaway. Because people generally contact their first and last names to create their handles.&lt;/li&gt;
&lt;li&gt;Next, with a 30% probability, I append some digits (maximum 3) after the result of Step 3. Why? Because not everyone in the Twitter-verse gets their handle of choice. They append random numbers to make it unique :)&lt;/li&gt;
&lt;li&gt;The result is appended to a “@” character.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And we have the handle ready! If you are wondering how do we do something with X% probability, it can be done easily by checking the result of &lt;code&gt;Math.random()&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
For example: To run a code with 70% probability, we could use &lt;code&gt;Math.random() &amp;gt; 0.3&lt;/code&gt;. This condition means we want the number returned by &lt;code&gt;Math.random()&lt;/code&gt; to be greater than 0.3. And &lt;code&gt;Math.random()&lt;/code&gt; return from 0 to 1. So basically we are checking that the returned number should be between 0.3 and 0.1. This translates to having a 70% chance:&lt;/p&gt;

&lt;p&gt;0 - 0.3 → 30% probably outcomes&lt;br&gt;&lt;br&gt;
0.3 - 1 → 70% probably outcomes&lt;/p&gt;

&lt;p&gt;Here is how the complete function looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getHandleFromName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Concatenating extracts from first and last name, with _ maybe?&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;handle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;_&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;lname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;lname&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;
  &lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Add some digits?&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;handle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;}${&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;999&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;// Append to @&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`@&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;handle&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Creating fake tweets - Final items
&lt;/h3&gt;

&lt;p&gt;To all the above data, we add random “like” count and tweet date. One more thing that the tweet shows is the image of the element on the website that failed the Accessibility guideline. Remember the issue structure that we get from the API? It had a key called &lt;code&gt;selector&lt;/code&gt; is the CSS selector of the corresponding element. I created another API to which I pass the CSS selector and website URL and it returns me the screenshot of that element. More on that later.&lt;/p&gt;

&lt;p&gt;And combining all the fake data, we generate this beautiful fake feedback tweet:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkushagra.dev%2Fimages%2F2019%2Fa11yformanagers-tweet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fkushagra.dev%2Fimages%2F2019%2Fa11yformanagers-tweet.png"&gt;&lt;/a&gt;Tweet screenshot of a fake user complaining about color contrast user&lt;/p&gt;

&lt;p&gt;That is it for this article. In &lt;a href="https://kushagra.dev/blog/case-study-accessibility-report-for-managers-p2/" rel="noopener noreferrer"&gt;the next article&lt;/a&gt;, I’ll go through the app’s backend and how it is deployed.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>tutorial</category>
      <category>frontend</category>
      <category>a11y</category>
    </item>
    <item>
      <title>Introducing CSSBattle PRO</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Fri, 12 Jul 2019 04:51:06 +0000</pubDate>
      <link>https://dev.to/chinchang/introducing-cssbattle-pro-4i1i</link>
      <guid>https://dev.to/chinchang/introducing-cssbattle-pro-4i1i</guid>
      <description>&lt;p&gt;We're proud to introduce &lt;a href="https://cssbattle.dev/pro" rel="noopener noreferrer"&gt;CSSBattle PRO&lt;/a&gt;, where you can upgrade your CSSBattle experience 🥳. For those who have not heard about CSSBattle before, CSSBattle is the first ever code-golfing game for CSS lovers. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://cssbattle.dev/pro" rel="noopener noreferrer"&gt;CSSBattle PRO&lt;/a&gt; gives you access to the following features:&lt;/p&gt;

&lt;h2&gt;
  
  
  Add plugins to the code editor 🔌
&lt;/h2&gt;

&lt;p&gt;With plugins, you can add custom scripts to enhance the editor and make it faster to reach the optimized solutions. For example, you can use it to automatically minify your code or convert the units to smaller character units. Here's a simple minification script to get you started:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;processedCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\&amp;lt;\!&lt;/span&gt;&lt;span class="sr"&gt;--&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;?[^\s&lt;/span&gt;&lt;span class="sr"&gt;?&lt;/span&gt;&lt;span class="se"&gt;\[][\s\S]&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;?&lt;/span&gt;&lt;span class="sr"&gt;--&lt;/span&gt;&lt;span class="se"&gt;\&amp;gt;&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\&amp;gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\/\*&lt;/span&gt;&lt;span class="sr"&gt;.*&lt;/span&gt;&lt;span class="se"&gt;\*\/&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\/\*[\s\S]&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;?\*\/&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\t&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\v&lt;/span&gt;&lt;span class="sr"&gt;|&lt;/span&gt;&lt;span class="se"&gt;\s{2,}&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\{\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\}\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\:\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\;\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\,\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\~\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;~&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\&amp;gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\+\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;+&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;*&lt;/span&gt;&lt;span class="se"&gt;\!\s&lt;/span&gt;&lt;span class="sr"&gt;*/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;processedCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Advanced target stats 📊
&lt;/h2&gt;

&lt;p&gt;Get a bird's-eye view on your performance in battles with these advanced stats. See where you're performing well and where you're lagging behind. Here's what it looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyrsa2ysqlr8257i9foe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiyrsa2ysqlr8257i9foe.png" alt="Advanced stats showing where you lag" width="800" height="243"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Light theme ☀️🌙
&lt;/h2&gt;

&lt;p&gt;This is one of our favourite features! You'll be able to switch between light and dark themes and customize the experience as you like. Here's what the light theme looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7phtqic732wji1a9qxzn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7phtqic732wji1a9qxzn.png" alt="Light theme on CSSBattle" width="800" height="503"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  PRO badge 🎖
&lt;/h2&gt;

&lt;p&gt;Apart from all the above features, you'll also get a shiny &lt;code&gt;PRO&lt;/code&gt; badge next to your name wherever it appears across CSSBattle. &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--91zC_FK2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cssbattle.dev/blog/images/2019/pro-badge.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--91zC_FK2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cssbattle.dev/blog/images/2019/pro-badge.svg" alt="Pro" width="30" height="17"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Upcoming features
&lt;/h2&gt;

&lt;p&gt;We're also planning to add these features very soon which will make your PRO experience even better.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create public community targets&lt;/strong&gt;: Create your own targets for the community with your own rules. All the targets will be rated by the community and we'll feature new targets every week.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Organize your own battles&lt;/strong&gt;: Create your own custom battles with your own targets or choose from the community targets. You can also make it invite only which is great for conferences or workplaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can upgrade to &lt;a href="https://cssbattle.dev/pro" rel="noopener noreferrer"&gt;CSSBattle PRO&lt;/a&gt; for $3/month (a special launch price). This price may change in the future depending upon features but will remain the same for you if you decide to upgrade now. &lt;/p&gt;

&lt;p&gt;We hope you enjoy CSSBattle PRO!&lt;/p&gt;

&lt;h2&gt;
  
  
  Giveaway 🎁
&lt;/h2&gt;

&lt;p&gt;To celebrate the launch, we are giving away 1 month free access to 5 lucky players who Retweet the following tweet!&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1149249241530929152-839" src="https://platform.twitter.com/embed/Tweet.html?id=1149249241530929152"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1149249241530929152-839');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1149249241530929152&amp;amp;theme=dark"
  }



&lt;/p&gt;

</description>
      <category>css</category>
      <category>game</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How I saved 100KB with React.lazy</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Fri, 05 Jul 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/chinchang/how-i-saved-100kb-with-react-lazy-59gm</link>
      <guid>https://dev.to/chinchang/how-i-saved-100kb-with-react-lazy-59gm</guid>
      <description>&lt;p&gt;This post is about how I was able to reduce my homepage JavaScript by more around 100KB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; : Use &lt;a href="https://reactjs.org/docs/code-splitting.html#reactlazy"&gt;&lt;code&gt;React.lazy&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://reactjs.org/docs/code-splitting.html#suspense"&gt;&lt;code&gt;React.Suspense&lt;/code&gt;&lt;/a&gt; to lazy load your non-critical dependencies&lt;/p&gt;

&lt;p&gt;I have a React app bootstrapped from &lt;a href="https://github.com/facebook/create-react-app"&gt;create-react-app&lt;/a&gt;. One of the page (just a React Component) in that app uses &lt;a href="https://codemirror.net/"&gt;CodeMirror&lt;/a&gt; (a code editor). The app uses &lt;a href="https://reacttraining.com/react-router/"&gt;react-router&lt;/a&gt; for routing. And so this page component, just like all other pages, is imported in the main &lt;code&gt;App&lt;/code&gt; component to provide to the router.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;App.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Home&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Home&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Page2&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./Page2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Route&lt;/span&gt; &lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/page2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;Page2&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Router&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Page2.js&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-codemirror&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Note&lt;/em&gt;: &lt;code&gt;react-codemirror&lt;/code&gt; actually does a named export. But for simplicity, I am assuming a default export.&lt;/p&gt;

&lt;p&gt;This situation leads to &lt;code&gt;Page2.js&lt;/code&gt; being a synchronous dependency to render &lt;code&gt;App.js&lt;/code&gt;. And &lt;code&gt;Page2.js&lt;/code&gt; in turn depends on &lt;code&gt;react-codemirror&lt;/code&gt;. So indirectly, &lt;code&gt;react-codemirror&lt;/code&gt; becomes a synchronous dependency to render &lt;code&gt;App.js&lt;/code&gt;. This basically means whatever page we visit, &lt;code&gt;react-codemirror&lt;/code&gt; will be fetched and parsed before the page renders. Even if Codemirror is not even being used on that page! Let's fix this.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solution
&lt;/h2&gt;

&lt;p&gt;The solution is pretty neat and easy. React recently introduced a new API: &lt;a href="https://kushagra.dev/blog/how-i-saved-100kbs-with-react-lazy/"&gt;&lt;code&gt;React.lazy&lt;/code&gt;&lt;/a&gt;. And an accompanying component called &lt;a href="https://kushagra.dev/blog/how-i-saved-100kbs-with-react-lazy/"&gt;&lt;code&gt;Suspense&lt;/code&gt;&lt;/a&gt;. Here is how we use them to fix our problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Make the import lazy
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Page2.js&lt;/code&gt; imports &lt;code&gt;react-codemirror&lt;/code&gt;. Ideally we want that &lt;code&gt;Page2.js&lt;/code&gt; should load &lt;code&gt;react-codemirror&lt;/code&gt; asynchronously when Page2 is actually visited.&lt;/p&gt;

&lt;p&gt;This is our current &lt;code&gt;Page2.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-codemirror&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Using the &lt;code&gt;React.lazy&lt;/code&gt; API, we can make the import lazy. Like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-codemirror&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And this just starts working out of the box! No more change required in the way &lt;code&gt;CodeMirror&lt;/code&gt; component is used. What you'll notice now is initially when you are on homepage, CodeMirror doesn't load. When you visit &lt;em&gt;/page2/&lt;/em&gt;, you see blank area where CodeMirror was to be rendered, for a short duration while CodeMirror loads asynchronously. And then when it has finished loading, &lt;code&gt;CodeMirror&lt;/code&gt; component renders.&lt;/p&gt;

&lt;p&gt;While CodeMirror is being fetched, there is just blank space where CodeMirror editor should have been present. That is not such a good experience as user is left without any information about that blank space. That is where &lt;code&gt;React.Suspense&lt;/code&gt; component comes into action.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Improve the blank space context
&lt;/h2&gt;

&lt;p&gt;Here is all we need to do to make the experience better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-codemirror&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Loading editor...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We wrap the asynchronous/lazy components with a &lt;code&gt;Suspense&lt;/code&gt; tag and give it a &lt;code&gt;fallback&lt;/code&gt; which should show instead of blank space. That is it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus tip
&lt;/h2&gt;

&lt;p&gt;There is one special requirement for using &lt;code&gt;React.lazy&lt;/code&gt; which you need to be aware of. It only works with component that have default &lt;a href="https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export"&gt;export&lt;/a&gt;. So components with named exports can't be lazily imported with it. But you might have components with named exports, what to do then? There is a small trick. Let's assume our &lt;code&gt;Page2.js&lt;/code&gt; file exported &lt;code&gt;Page2&lt;/code&gt; component so that it was initially imported as &lt;code&gt;import {CodeMirror} from 'react-codemirror'&lt;/code&gt;. In that case, we can use &lt;code&gt;React.lazy&lt;/code&gt; on it as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;lazy&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-codemirror&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="p"&gt;}))&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Loading editor...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;CodeMirror&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What we did here is once we import the named module, inside the &lt;code&gt;then&lt;/code&gt; callback we turn it into a seemingly default exported module - an object with the module available on &lt;code&gt;default&lt;/code&gt; key.&lt;/p&gt;

&lt;p&gt;Side note, this app is &lt;a href="https://cssbattle.dev"&gt;CSSBattle&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;That's all folks! Go shave off some unnecessary bytes of your pages. If you have any questions or comments, ask me here or on Twitter &lt;a href="https://twitter.com/chinchang457"&gt;@chinchang457&lt;/a&gt; (DMs are open).&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>Let's build a Perfect CSS Framework</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Wed, 03 Jul 2019 08:24:50 +0000</pubDate>
      <link>https://dev.to/chinchang/let-s-build-a-perfect-css-framework-4n7h</link>
      <guid>https://dev.to/chinchang/let-s-build-a-perfect-css-framework-4n7h</guid>
      <description>&lt;p&gt;This is an experiment I am doing to build a theoretically perfect CSS framework for teams. Here is how it goes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You comment on this discussion with a problem/issue we currently face with writing CSS (with vanilla CSS or any library).&lt;/li&gt;
&lt;li&gt;I'll reply (or anyone of you can too) with what can be the probable solutions to that issue.&lt;/li&gt;
&lt;li&gt;In the end, we collect all those suggested solutions to build or search that "Perfect CSS Framework".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Sounds good? I'll start.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>css</category>
      <category>framework</category>
    </item>
    <item>
      <title>An interactive and practical introduction to Web Accessibility for everyone</title>
      <dc:creator>Kushagra Gour</dc:creator>
      <pubDate>Tue, 02 Jul 2019 00:00:00 +0000</pubDate>
      <link>https://dev.to/chinchang/an-interactive-and-practical-introduction-to-web-accessibility-22o1</link>
      <guid>https://dev.to/chinchang/an-interactive-and-practical-introduction-to-web-accessibility-22o1</guid>
      <description>&lt;p&gt;Ever since I understood the importance of Accessibility, I have always tried putting a conscious effort to share whatever I keep learning. So that everyone can start caring about at least the basics of Accessibility while making websites.&lt;/p&gt;

&lt;p&gt;Nothing brings you closer to reality than actually facing it. This is the premise of my latest attempt to spread awareness about Web Accessibility. &lt;/p&gt;

&lt;p&gt;Presenting 👉🏼 &lt;a href="https://introtoaccessibility.com/"&gt;introtoaccessibility.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This project is a series of chapters, in the form of a quiz. Each chapter shows you something or ask you to do something and then asks you a question. The chapters are basically extreme cases of unusable user experience designed such that they are inaccessible even to abled users.&lt;/p&gt;

&lt;p&gt;Each chapter makes you experience a particular Accessibility issue. It then tells you how that issue affects various users on the Internet, why it affects them and what you can do to prevent it.&lt;/p&gt;

&lt;p&gt;My intention with this project is that it &lt;strong&gt;can be the first step to introduce Web Accessibility to anyone and everyone who work with websites&lt;/strong&gt;. No matter if they are developers, designers or marketers! I hope I can arouse empathy that each one of us requires to make the Web a better place for everyone.&lt;/p&gt;

&lt;p&gt;Please do share with anyone and everyone you know who works with websites -&amp;gt; &lt;a href="https://introtoaccessibility.com/"&gt;introtoaccessibility.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see my other projects here -&amp;gt; &lt;a href="https://kushagra.dev/lab/"&gt;https://kushagra.dev/lab/&lt;/a&gt;&lt;br&gt;
And follow me on Twitter -&amp;gt; &lt;a href="https://twitter.com/chinchang457"&gt;@chinchang457&lt;/a&gt; where I share more such stuff.&lt;br&gt;
Also, I recently launched a &lt;a href="https://github.com/chinchang/ask-me-anything"&gt;"Ask me Anything" on Github&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
