<?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>Forem: michalhonc</title>
    <description>The latest articles on Forem by michalhonc (@michalhonc).</description>
    <link>https://forem.com/michalhonc</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%2F139302%2F023f22c3-a25a-4353-9702-f76624f51975.jpg</url>
      <title>Forem: michalhonc</title>
      <link>https://forem.com/michalhonc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/michalhonc"/>
    <language>en</language>
    <item>
      <title>Open native share context with Javascript</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Mon, 23 Nov 2020 07:54:14 +0000</pubDate>
      <link>https://forem.com/michalhonc/open-native-share-context-with-javascript-3j7b</link>
      <guid>https://forem.com/michalhonc/open-native-share-context-with-javascript-3j7b</guid>
      <description>&lt;h1&gt;
  
  
  Share text, links, and files to other OS apps with Javascript share API
&lt;/h1&gt;

&lt;p&gt;Surely you have already used Share API in mobile native apps. It's the popup menu with all apps that can receive share context with the addition of locations like a copy to clipboard. This API is well known in &lt;a href="https://developer.apple.com/design/human-interface-guidelines/ios/extensions/sharing-and-actions/"&gt;iOS&lt;/a&gt; and &lt;a href="https://developer.android.com/training/sharing/"&gt;Android&lt;/a&gt; (&lt;a href="https://reactnative.dev/docs/share"&gt;React Native&lt;/a&gt; and &lt;a href="https://docs.expo.io/versions/latest/sdk/sharing/"&gt;Expo&lt;/a&gt;) but did you know that you can trigger the same popup via browser API?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bq4FFYeL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://webdev.imgix.net/web-share/wst-send.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bq4FFYeL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://webdev.imgix.net/web-share/wst-send.png" alt="Share Context API on iOS"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The W3C specification is still a draft but well supported by the browsers. It's mostly available in mobile browsers (makes sense) but Safari on macOS and Edge on Windows do support it for desktop at time of writing (11-2020).&lt;/p&gt;

&lt;h2&gt;
  
  
  API
&lt;/h2&gt;

&lt;p&gt;The API consists of two functions on &lt;code&gt;navigator&lt;/code&gt; object. The first function is &lt;code&gt;share()&lt;/code&gt; which takes a data object as a single parameter. You can pass the following to this object&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;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;USVString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;USVString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;USVString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nx"&gt;fiels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Files&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;blockquote&gt;
&lt;p&gt;USVString is a sequence of Unicode scalar values. Simply USVString is a sequence of numbers that are represented by a related characters in the Unicode standard.&lt;br&gt;
Image, video, audio, and text files can be shared&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This function returns a promise that is resolved once the user completed a share action. Rejected can be when the user closed the share context popup or when the specified data parameter is not valid. This API works only for HTTPS protocol and only after the user interacted with the page, ie. you can not init share popup onload.&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="c1"&gt;// async context is present&lt;/span&gt;
&lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;await&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;share&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Share API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;This API is cool!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;url&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://example.com&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="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&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;To check if a given file array can be shared, use the &lt;code&gt;canShare()&lt;/code&gt; function that takes an object as a parameter with an interface:&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;files&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Files&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;Usage may be following:&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="c1"&gt;// in HTML&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;file&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// …&lt;/span&gt;
&lt;span class="c1"&gt;// async context is present&lt;/span&gt;
&lt;span class="c1"&gt;// Event Handler&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;files&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&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;navigator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;canShare&lt;/span&gt;&lt;span class="p"&gt;?.({&lt;/span&gt; &lt;span class="nx"&gt;files&lt;/span&gt; &lt;span class="p"&gt;}))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&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;share&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Pictures&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Our Pictures.&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that &lt;code&gt;canShare()&lt;/code&gt; has lesser support than &lt;code&gt;share()&lt;/code&gt;!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Fallback
&lt;/h2&gt;

&lt;p&gt;For browsers that do not support this API should be available a fallback. Either the share button is not shown or a custom popup is presented to the user. Such popup can consist of options such as copy to clipboard, share on social media, open in a mail client (anchor with the mailto prefix as href) or &lt;a href="https://stackoverflow.com/questions/6480462/how-to-pre-populate-the-sms-body-text-via-an-html-link"&gt;paste it to message&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Links for implementation of custom share behavior for social media:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.twitter.com/en/docs/twitter-for-websites/tweet-button/overview"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.facebook.com/docs/plugins/share-button/"&gt;Facebook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;With Share API users can customize their preferred share targets on their own device instead of being limited to just the predefined options.&lt;/p&gt;

&lt;h2&gt;
  
  
  Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://w3c.github.io/web-share/"&gt;W3C Specification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share"&gt;MDN Docs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.dev/web-share/"&gt;Web Dev Post&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>share</category>
      <category>api</category>
      <category>browser</category>
    </item>
    <item>
      <title>4 not so crucial things I didn't know about JavaScript</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Sat, 01 Aug 2020 16:33:36 +0000</pubDate>
      <link>https://forem.com/michalhonc/4-not-so-crucial-things-i-didn-t-know-about-javascript-32fi</link>
      <guid>https://forem.com/michalhonc/4-not-so-crucial-things-i-didn-t-know-about-javascript-32fi</guid>
      <description>&lt;p&gt;There is so many things that you don't know about JavaScript. Some are crucial, some are not. I wanted to put some not so crucial observations that I didn't know about JavaScript to blog post. Hope you will find them interesting. Let's get to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Just plain scope
&lt;/h2&gt;

&lt;p&gt;Thing number one in this list is that you can use just plain { ... } scope whenever you want.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Big Lebowski&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="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Big Lebowski&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;nickname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;The Dude&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="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;nickname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Walter&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="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nickname&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// ReferenceError: nickname is not defined&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This preserves the same functionality as other scopes with&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, etc. But why would you use plain scope? Exactly why you are using lexical scoping in eg. &lt;code&gt;function&lt;/code&gt; or &lt;code&gt;if&lt;/code&gt; statements. To scope variables so they are not accessible from outer scope to prevent naming collision and keep things seperate. You can use these plain scopes to follow the &lt;a href="https://en.wikipedia.org/wiki/Principle_of_least_privilege"&gt;principle of least privilege&lt;/a&gt;. Not once did I come across upon such usage in any codebase that I run into but that doesn't mean it's useless.&lt;/p&gt;

&lt;h2&gt;
  
  
  There is no &lt;code&gt;else if&lt;/code&gt; in JS!
&lt;/h2&gt;

&lt;p&gt;Wait, what?! I have used &lt;code&gt;else if&lt;/code&gt; so many times and now it doesn't exist in JavaScript? The construction &lt;code&gt;else if&lt;/code&gt; doesn't exists in the language AS IS. Only &lt;code&gt;if / else&lt;/code&gt; exists. But how can I use &lt;code&gt;else if&lt;/code&gt; then? Answer is easier that you might think. You just omit curly braces after &lt;code&gt;else&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// is actualy following but with omitted curly braces after else&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;b&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;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;c&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&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;Omitting curly braces is not anything special in JavaScript. Recall this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;name&lt;/span&gt; &lt;span class="o"&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="nx"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;lastName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Again, this is not anything crucial for your day to day life but just a fun fact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Naming loops and other statements! WHAT?!
&lt;/h2&gt;

&lt;p&gt;You can label JavaScript statement to afterwards use &lt;code&gt;break&lt;/code&gt; or &lt;code&gt;continue&lt;/code&gt; with the label.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;loop1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;//The first for statement is labeled "loop1"&lt;/span&gt;
   &lt;span class="nl"&gt;loop2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
   &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;j&lt;/span&gt;&lt;span class="o"&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;//The second for statement is labeled "loop2"&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;j&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="p"&gt;{&lt;/span&gt;
         &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="nx"&gt;loop1&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;You can also use them with those plain scopes I mentioned at the beginning of this post.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;someScope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ..&lt;/span&gt;
    &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="nx"&gt;someScope&lt;/span&gt;
    &lt;span class="c1"&gt;// anything after break won't be executed&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Again, I have not seen naming with label in any real codebase but that doesn't mean it doesn't have an use case for you in future.&lt;/p&gt;

&lt;h2&gt;
  
  
  There is negative zero!
&lt;/h2&gt;

&lt;p&gt;Yes, there is &lt;code&gt;-0&lt;/code&gt; and it is valid.  Since JavaScript uses &lt;a href="https://en.wikipedia.org/wiki/IEEE_754"&gt;IEEE 754 standard&lt;/a&gt; there are signed zeros (-0 and +0) and they are equal!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can still tell the difference with following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;is&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&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;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="c1"&gt;// or&lt;/span&gt;
&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/-&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// false (1/0 === Infinity and 1/-0 === -Infinity)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Where negative zero occurs? In certain numeric operations such as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// -0&lt;/span&gt;
&lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// -0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Another case is using negative zero with vector logic where besides value you also needs to know the direction of the value.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Do you know the difference between inherit, initial, unset, and.. And revert?</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Tue, 19 May 2020 05:01:17 +0000</pubDate>
      <link>https://forem.com/michalhonc/do-you-know-the-difference-between-inherit-initial-unset-and-and-revert-3jen</link>
      <guid>https://forem.com/michalhonc/do-you-know-the-difference-between-inherit-initial-unset-and-and-revert-3jen</guid>
      <description>&lt;p&gt;Do you know what the differences are between the four CSS values for controlling the inheritance of the rules? This article will present them to you and explain when to use what value in a given situation.&lt;/p&gt;

&lt;p&gt;For each CSS property, these values are valid. In order to fulfill understanding how these values work, it takes explaining when a property is inherited and when it is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Inherited properties
&lt;/h2&gt;

&lt;p&gt;Inherited properties are those properties that, when not specified, take the value of the property from the parent element. An example may be the property &lt;code&gt;color&lt;/code&gt; If we set that to a &lt;code&gt;html&lt;/code&gt; element, all child elements that don't have the &lt;code&gt;color&lt;/code&gt; property inherit the value from the &lt;code&gt;html&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;footer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&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;In this case, all the text, except the footer, will be blue. The footer will have red text.&lt;/p&gt;

&lt;p&gt;If the CSS property has not been set anywhere, its value is taken from the default styles.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="nt"&gt;footer&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&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;In the case of Chrome, the all-purpose text will be black except for the footer as the default color of the property &lt;code&gt;color&lt;/code&gt; is black.&lt;/p&gt;

&lt;h2&gt;
  
  
  Non-inherited properties
&lt;/h2&gt;

&lt;p&gt;The opposite are properties that are not inherited. Unless we specify such a property. Its value will be set from the default styles.&lt;/p&gt;

&lt;p&gt;We will use the &lt;code&gt;border&lt;/code&gt; nature as an example. If we set that to a &lt;code&gt;html&lt;/code&gt; element, only a &lt;code&gt;html&lt;/code&gt; element will have that value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;footer&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;No other element will have a blue border. The footer does not have the &lt;code&gt;border&lt;/code&gt; set, so it will use the default value. The footer will have the value of the CSS property of &lt;code&gt;border&lt;/code&gt; equal to &lt;code&gt;none&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  inherit
&lt;/h2&gt;

&lt;p&gt;The first value we explain is &lt;code&gt;inherit&lt;/code&gt;. It creeps out from its name that if it specifies a property for CSS, it will take the value from the parent element. So, for inherited qualities, it sets their guiding behavior. For example, it finds practical uses when resetting a value in media query. For non-inherited properties, this value can also be set, but in practice I have not yet encountered a situation where it would be suitable for use.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;lightgrey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;inherit&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;h2&gt;
  
  
  initial
&lt;/h2&gt;

&lt;p&gt;If you don't need to use inheritance, you use the value &lt;code&gt;initial&lt;/code&gt;. That given CSS property sets the default value given in the specification. This makes the element with this homeliness independent of the parent element and its value of the same CSS property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;initial&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;
  
  
  unset
&lt;/h2&gt;

&lt;p&gt;The combination of the two above values is &lt;code&gt;unset&lt;/code&gt;. After setting the CSS property, &lt;code&gt;unset&lt;/code&gt; acts dependent on whether the given CSS property is inherited or not. If the CSS property is inherited (e.g. &lt;code&gt;color&lt;/code&gt;), The CSS property will behave as if it has a value of &lt;code&gt;inherity&lt;/code&gt;, i.e. it will inherit the value from the parent element. If the CSS property is not hereditary (e.g. &lt;code&gt;boder&lt;/code&gt;), The CSS property will behave like a value of &lt;code&gt;initial&lt;/code&gt;. It is therefore a combination of &lt;code&gt;intial&lt;/code&gt; and &lt;code&gt;inheritance&lt;/code&gt; that does not change its inherited behaviour for a given CSS property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;green&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;red&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;600px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* -&amp;gt; green */&lt;/span&gt;
      &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* -&amp;gt; none */&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;
  
  
  revert
&lt;/h2&gt;

&lt;p&gt;Revert is a whole new value currently (18-05-2020) supported only in Firefox and Safari. It behaves very much like &lt;code&gt;unset&lt;/code&gt;. The difference is that &lt;code&gt;revert&lt;/code&gt; versus &lt;code&gt;unset&lt;/code&gt; can refer to maximum user agent stylesheet. This means that the value specified in the specification is not taken as &lt;code&gt;initial&lt;/code&gt;. This makes a difference, for example, with the property &lt;code&gt;display&lt;/code&gt; for paragraph. Its value in the specification is &lt;code&gt;inline&lt;/code&gt;, whereas the default browser value for the section is &lt;code&gt;block&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* -&amp;gt; inline */&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;revert&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;/* -&amp;gt; block */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  all
&lt;/h2&gt;

&lt;p&gt;We explained all the values by which the current value can be reset. These values also include one CSS property, namely &lt;code&gt;all&lt;/code&gt;. This property sets &lt;code&gt;original / inherit / unset / revert&lt;/code&gt; to all CSS properties of the element. So it is not necessary to list all the properties.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c"&gt;/* vs */&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nl"&gt;all&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;unset&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;Hope it helps :-)&lt;/p&gt;

&lt;p&gt;Find more tips on my twitter &lt;a href="https://twitter.com/Michalhonc"&gt;@michalhonc&lt;/a&gt;, instagram &lt;a href="https://www.instagram.com/michalhonc.cz/"&gt;@michalhonc.cz&lt;/a&gt; and personal blog &lt;a href="https://michalhonc.cz"&gt;https://michalhonc.cz&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>inheritance</category>
    </item>
    <item>
      <title>Super Cool and Super Useless Secret Chrome Feature</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Thu, 23 Apr 2020 15:51:30 +0000</pubDate>
      <link>https://forem.com/michalhonc/super-cool-and-super-useless-secret-chrome-feature-3210</link>
      <guid>https://forem.com/michalhonc/super-cool-and-super-useless-secret-chrome-feature-3210</guid>
      <description>&lt;p&gt;Debugging a website inside DevTools is crucial.&lt;/p&gt;

&lt;p&gt;But what if you are developing DevTools? How do you debug that?!&lt;/p&gt;

&lt;p&gt;Well with DevTools within DevTools ofcourse! DevTools are just another HTML page so you can open another DevTools!&lt;/p&gt;

&lt;p&gt;Just open DevTools in separet window and press &lt;code&gt;Command+Option+I&lt;/code&gt; for Mac and &lt;code&gt;F12&lt;/code&gt; or &lt;code&gt;Control+Shift+I&lt;/code&gt; for Linux/Windows. You will get another window!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KW7N6Rw3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ntu0zbe7l5ud2rr097zz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KW7N6Rw3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ntu0zbe7l5ud2rr097zz.gif" alt="How to open DevTools in DevTools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For you as a web dev it's probably useless. But can be handy for DevTools devs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CD2Xnax9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2aomh64l4hrgcyv4u4wb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CD2Xnax9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2aomh64l4hrgcyv4u4wb.jpg" alt="Spiderman Meme"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devtools</category>
      <category>secret</category>
      <category>hack</category>
    </item>
    <item>
      <title>Skyrocket your CSS skills with Spaced Repetition</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Thu, 16 Apr 2020 17:26:43 +0000</pubDate>
      <link>https://forem.com/michalhonc/skyrocket-your-css-skills-with-spaced-repetition-ok7</link>
      <guid>https://forem.com/michalhonc/skyrocket-your-css-skills-with-spaced-repetition-ok7</guid>
      <description>&lt;p&gt;What if I tell you that there is a way to either greatly decrease your time spent studying, or greatly increase the amount you learn? Doesn't matter if it's CSS, HTML or geography.&lt;/p&gt;

&lt;h2&gt;
  
  
  How?
&lt;/h2&gt;

&lt;p&gt;I was never able to study in a way of memorizing stacks of texts. I need some sort of game that can keep me entertained while studying. I have recently tripped over term called Spaced Repetition. Spaced repetition is a study method which uses spacing effect which describes how our brains make better connections and overall remember things more effectively when we space out our learning over time.&lt;/p&gt;

&lt;p&gt;The following curve better describes the review cycle that can help memorizing topic for longer period of time.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nC3JbIBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cl8jnspqrfn4425fupcq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nC3JbIBZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cl8jnspqrfn4425fupcq.png" alt="Forgetting curve"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To apply Spaced repetition in studying, I use an app called &lt;a href="https://apps.ankiweb.net/"&gt;Anki&lt;/a&gt;. It's multiplatform (Web, Android, iOS (paid), Mac, Windows and Linux) app that is based on flash cards.&lt;/p&gt;

&lt;p&gt;In Anki I've created multiple Decks (topics) with multiple questions about CSS.&lt;br&gt;
Namely these decks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CSS properties&lt;/li&gt;
&lt;li&gt;CSS pseudo-elements&lt;/li&gt;
&lt;li&gt;CSS pseudo-classes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can download them on my Github repo, simply import them to Anki and start studying!&lt;/p&gt;

&lt;p&gt;There are some advanced stuff in those decks that I was not aware it even exists.&lt;/p&gt;

&lt;p&gt;Link to repo: &lt;a href="https://github.com/michalhonc/anki__decks"&gt;https://github.com/michalhonc/anki__decks&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me know which decks should I create next! React? NodeJS? HTML elements?&lt;/p&gt;

</description>
      <category>css</category>
      <category>learning</category>
      <category>anki</category>
    </item>
    <item>
      <title>Set up continuous deploy for Free with React, Github, Travis and Heroku</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Wed, 08 Apr 2020 17:02:47 +0000</pubDate>
      <link>https://forem.com/michalhonc/set-up-continuous-deploy-for-free-with-react-github-travis-and-heroku-381b</link>
      <guid>https://forem.com/michalhonc/set-up-continuous-deploy-for-free-with-react-github-travis-and-heroku-381b</guid>
      <description>&lt;p&gt;In this tutorial I'll show you how to set up professional development process with help of continuous deployment.&lt;/p&gt;

&lt;p&gt;We'll be using React with help of &lt;a href="https://create-react-app.dev/" rel="noopener noreferrer"&gt;Create-react-app&lt;/a&gt; but you can easily follow with any other project maintained with NPM. Even if you are not using NPM, you can adjust the core build and run scripts for your needs quite easily. By any means you don't have to have any React experience whatsoever. It's just a sample project that will be used to show the flow of setting up the environment.&lt;/p&gt;

&lt;p&gt;Requirements before we start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Installed &lt;a href="https://nodejs.org/en/download/" rel="noopener noreferrer"&gt;NodeJS&lt;/a&gt; with NPM and &lt;a href="https://git-scm.com/" rel="noopener noreferrer"&gt;Git&lt;/a&gt;,&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You have to have an account on &lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, Github account linked with &lt;a href="https://travis-ci.org/" rel="noopener noreferrer"&gt;Travis-ci.org&lt;/a&gt; and &lt;a href="https://www.heroku.com/" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt;. All of them are free. Travis CI has .org TLD for free repos and .com TLD for private repos. For this tutorial we'll use .org version for free repos.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Create React project with Create-React-App
&lt;/h2&gt;

&lt;p&gt;Open your terminal of choice in your work folder. For me, it's &lt;code&gt;~/sandbox/&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; ~/sandbox/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within this folder, we'll create the React project with NPX (A tool for executing Node packages) that is pre-installed with NPM version 5.2+&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app tutorial-cicd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installation of boilerplate project will begin. When everything is good to go you'll see a message with list of commands that can be run within the app. We'll just &lt;code&gt;cd&lt;/code&gt; into the project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;tutorial-cicd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We don't have to do &lt;code&gt;npm install&lt;/code&gt; since the &lt;code&gt;npx&lt;/code&gt; command already dit it. Now we can start the app with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;New browser tab will get open with &lt;code&gt;http://localhost:3000&lt;/code&gt; and following page will be shown.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxanj32ft93ung7w5ziny.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxanj32ft93ung7w5ziny.png" alt="Create-react-app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The good thing about create-react-app is that it has tests included out of the box so we don't have to set up anything. For the reference you can run tests within you folder with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll be prompted with few options of running your tests. Simple press &lt;code&gt;a&lt;/code&gt; to run all tests. Only one test should be run with text &lt;code&gt;renders learn react link&lt;/code&gt; that checks if the app renders link that can be seen on &lt;code&gt;http://localhost:3000&lt;/code&gt;. Since React renders the link just fine, the test passes.&lt;/p&gt;

&lt;p&gt;Now we have our project setup.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Github repo and link it to our app
&lt;/h2&gt;

&lt;p&gt;If you already setup your Github account you are good to go, if not please register on &lt;a href="https://github.com" rel="noopener noreferrer"&gt;Github.com&lt;/a&gt;. After you login to Github, we'll create new repository. You can create new repository on &lt;a href="https://github.com/new" rel="noopener noreferrer"&gt;https://github.com/new&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We'll name the repository &lt;code&gt;tutorial-cicd&lt;/code&gt; and set it to &lt;code&gt;Public&lt;/code&gt;. Now we have repo created but still not linked to our app. We can do that with following commands&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git remote add origin git@github.com:&amp;lt;your_github_username&amp;gt;/tutorial-cicd.git
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NOTE that you should swap &lt;code&gt;&amp;lt;your_github_username&amp;gt;&lt;/code&gt; in first command with your username. Also this way we are using SSH to connect our repo. If you don't want to use SSH auth you can use HTTPS versions.&lt;/p&gt;

&lt;p&gt;We don't have to do &lt;code&gt;git init&lt;/code&gt; since npx already included &lt;code&gt;.git&lt;/code&gt; and &lt;code&gt;.gitignore&lt;/code&gt; in our app folder.&lt;/p&gt;

&lt;p&gt;If you've done everything correctly, you should see the app on Github under project &lt;code&gt;tutorial-cicd&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We have now working app that is connected to Github repo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect Github repo with Travis CI
&lt;/h2&gt;

&lt;p&gt;Now comes the part where we connect the repo with Travis CI. You should be logged in into Travis CI with the same Github account that has our &lt;code&gt;tutorial-cicd&lt;/code&gt; repo. You'll be afterwards redirected to Github for authorization.&lt;/p&gt;

&lt;p&gt;After you have successfully logged in. Click on your profile logo in the upper right side of the dashboard, click &lt;code&gt;Settings&lt;/code&gt; and then the green &lt;code&gt;Activate&lt;/code&gt; button. After that you should see a list of repositories on your Github account. If you don't see the &lt;code&gt;tutorial-cicd&lt;/code&gt; repo, click on &lt;code&gt;Sync account&lt;/code&gt; in the left side of the screen. It'll take few mins (don't know why it takes so much time to sync) to sync Github and Travis CI. After success you should see the &lt;code&gt;tutorial-cicd&lt;/code&gt; repo.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4j5zvijx1rlfkk934v3s.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4j5zvijx1rlfkk934v3s.png" alt="Success Travis CI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Travis config file
&lt;/h2&gt;

&lt;p&gt;To tell Travis CI what to do, we must create &lt;code&gt;.travis.yml&lt;/code&gt; config file in our projects root directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch&lt;/span&gt; .travis.yml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Within this file, we will specify language to be used in build, its version and script to be run.&lt;/p&gt;

&lt;p&gt;Since we need JavaScript on server, we will use Node.js v12. For this demo we will run only our test and production build of create-react-app so we can add following to .travis.yml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node_js&lt;/span&gt;

&lt;span class="na"&gt;node_js&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;12"&lt;/span&gt;

&lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm test&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm run build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's try that. Push new file to Github repo with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add travis.yml config file"&lt;/span&gt;
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you visit &lt;code&gt;tutorial-cicd&lt;/code&gt; in Travis on URL&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://travis-ci.org/github/&amp;lt;your-github-name&amp;gt;/tutorial-cicd&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You should see either running (yellow) build, already finished build (green), or failed build (red).&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpy8p9xdy0p5otndgqwtr.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpy8p9xdy0p5otndgqwtr.png" alt="Build Travis CI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Under it, there is a log of the build. If something failed, you will see there the appropriate error message.&lt;/p&gt;

&lt;p&gt;If everything passed, you just run first build! Good job&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Heroku project
&lt;/h2&gt;

&lt;p&gt;Now we will create project on Heroku where we can run our app in the cloud. For that you need to create an account on their &lt;a href="https://heroku.com" rel="noopener noreferrer"&gt;website&lt;/a&gt;. After you create and account, create new app on this &lt;a href="https://dashboard.heroku.com/new-app" rel="noopener noreferrer"&gt;link&lt;/a&gt;. Name the app as "-tutorial-cicd" and choose a region that is closer to your location. For me Europe. If the app name is already taken, just modify it slightly. Click "Create app".&lt;/p&gt;

&lt;h3&gt;
  
  
  Map Deployment Method to Github
&lt;/h3&gt;

&lt;p&gt;To link Heroku project with you Github repo, in the Herokus Deployment method, choose Github. Then find the Github repo project and connect it. In the Automatic deploys section, check the "Wait for CI to pass before deploy" and then click on "Enable Automatic Deploys".&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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2j74w6imniz8bholk2ml.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%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2j74w6imniz8bholk2ml.png" alt="Heroku Success Deployment Method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Link Travis and Heroku
&lt;/h2&gt;

&lt;p&gt;To connect Travis and Heroku, we need to update .travis.yml file. But before updating the file, we need to create our secure api key. For this, you need to have both &lt;a href="https://devcenter.heroku.com/articles/heroku-cli" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt; and &lt;a href="https://github.com/travis-ci/travis.rb#readme" rel="noopener noreferrer"&gt;Travis&lt;/a&gt; CLI. After installation login to heroku CLI with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;heroku login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That will prompt you with e-mail and password for Heroku.&lt;/p&gt;

&lt;p&gt;If you have both CLIs installed you will run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;travis encrypt &lt;span class="si"&gt;$(&lt;/span&gt;heroku auth:token&lt;span class="si"&gt;)&lt;/span&gt; &lt;span class="nt"&gt;--add&lt;/span&gt; deploy.api_key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will verify detected repository with &lt;code&gt;yes&lt;/code&gt;. Then it will prompt you what the CLI will overwrite our Travis config file with &lt;code&gt;deploy&lt;/code&gt; part. Answer with &lt;code&gt;y&lt;/code&gt;. At last we will specify provider of our deploy to be heroku and app name. Final .travil.yml config file should look like this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;language&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node_js&lt;/span&gt;

&lt;span class="na"&gt;node_js&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;12'&lt;/span&gt;

&lt;span class="na"&gt;script&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm test&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;npm run build&lt;/span&gt;

&lt;span class="na"&gt;deploy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;provider&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;heroku&lt;/span&gt;
  &lt;span class="na"&gt;app&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;your_heroku_app_name&amp;gt;&lt;/span&gt;
  &lt;span class="na"&gt;api_key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;secure&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;your_secure_key&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can push changes to Github repo with&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add deploy section to travis.yml"&lt;/span&gt;
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Serve static files on Heroku
&lt;/h2&gt;

&lt;p&gt;We have build our create-react-app to production version but we have not specified how to run such build. For that we will use &lt;code&gt;serve&lt;/code&gt; package. Sure there are better ways to do that but I have chosen the most straightforward for this tutorial. We need to install one extra dependency to our project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; serve
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that we will change our &lt;code&gt;start&lt;/code&gt; script in &lt;code&gt;package.json&lt;/code&gt; to use our installed &lt;code&gt;serve&lt;/code&gt; package as following&lt;/p&gt;

&lt;p&gt;NOTE: only edit &lt;code&gt;start&lt;/code&gt; in &lt;code&gt;scripts&lt;/code&gt; object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"serve -s build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-scripts build"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-scripts test"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"eject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"react-scripts eject"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can again commit new changes&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"add serve package"&lt;/span&gt;
git push
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After success CI in Travis, you should be able to see you app running on URL&lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://&amp;lt;your_heroku_app_name&amp;gt;.herokuapp.com/&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;You have now setup continuous deployment that will deploy your changes to production without human intervention. Only failed tests or build will need additional steps. Remember that you should create new git branch when developing new feature so another college can check your changes before they are deployed to production.&lt;/p&gt;

&lt;p&gt;My full repo can be found on my &lt;a href="https://github.com/michalhonc/tutorial-cicd" rel="noopener noreferrer"&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Going to create another tutorial on same process, but also with Docker! Stay tuned&lt;/p&gt;

&lt;p&gt;Checkout more articles on my &lt;a href="https://michalhonc.cz/en" rel="noopener noreferrer"&gt;personal blog&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>travis</category>
      <category>heroku</category>
      <category>continuousdeploy</category>
    </item>
    <item>
      <title>5 Canny little tricks for React devs</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Sat, 21 Mar 2020 17:36:31 +0000</pubDate>
      <link>https://forem.com/michalhonc/5-canny-little-tricks-for-react-devs-2bjj</link>
      <guid>https://forem.com/michalhonc/5-canny-little-tricks-for-react-devs-2bjj</guid>
      <description>&lt;p&gt;No extra talking. Let's get to it.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Pretty print your props.
&lt;/h2&gt;

&lt;p&gt;You just created new component that has massive amount of props. To quickly get your head around them you can pretty print them on page with more arguments on native JSON.stringify function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;NewComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&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="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;pre&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  2. Solve multiple HOC around a component?
&lt;/h2&gt;

&lt;p&gt;You cannot use hooks for some reason so you end up with HOC (Higher Order Components). That can get hairy in no time. Use compose function to clean your code. You can create your own or if you use redux you can import one from it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nx"&gt;i18n&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;format&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;)));&lt;/span&gt;

&lt;span class="c1"&gt;// vs.&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;compose&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="s1"&gt;redux&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// or your implementation&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;enhance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;compose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mapStateToProps&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;mapDispatchToProps&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nx"&gt;i18n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="nx"&gt;format&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;enhance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;






&lt;h2&gt;
  
  
  3. console.log function that uses concise body (body without return statement).
&lt;/h2&gt;

&lt;p&gt;You have function component that use concise body so you immidietely return body without the need of &lt;code&gt;return&lt;/code&gt; statement. Pretty cool time saver.. but what about the time you want to console.log props. You would have to convert it to block body with return statement. Or not? Actually you can use condtional logic for it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;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;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
   &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This both logs &lt;code&gt;props&lt;/code&gt; to console and render the component because console.log returns falsy value so it skips to second part of the condition.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Manually restart nodemon
&lt;/h2&gt;

&lt;p&gt;Sometimes you want to restart nodemon server manually. Instead of some random change to a random file and Ctrl + S just type &lt;code&gt;rs&lt;/code&gt; with a carriage return (Enter) to the terminal running nodemon. It will restart.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Pass HTML character references as props
&lt;/h2&gt;

&lt;p&gt;Want to pass HTML character references as props in JSX? It works with simple string but breaks with more complex logic. You can achieve it with String.fromCharCode function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// &amp;lt;Component charCode={160} /&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// 160 -&amp;gt; non-breaking space&lt;/span&gt;

&lt;span class="kd"&gt;const&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;props&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;divider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromCharCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;charCode&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
         &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;SubComponent&lt;/span&gt; &lt;span class="na"&gt;text&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;divider&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;divider&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&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;Find more tricks on my Twitter!&lt;br&gt;
&lt;a href="https://twitter.com/Michalhonc"&gt;https://twitter.com/Michalhonc&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>tricks</category>
    </item>
    <item>
      <title>Bypass AdBlock! (Not a single F*ckAdBlock plugin given)</title>
      <dc:creator>michalhonc</dc:creator>
      <pubDate>Sat, 08 Feb 2020 12:39:05 +0000</pubDate>
      <link>https://forem.com/michalhonc/bypass-adblock-not-a-single-f-ckadblock-plugin-given-4bme</link>
      <guid>https://forem.com/michalhonc/bypass-adblock-not-a-single-f-ckadblock-plugin-given-4bme</guid>
      <description>&lt;p&gt;Full version (without ads :-)) is accessible on my blog &lt;a href="http://bit.ly/bypass-adblock"&gt;http://bit.ly/bypass-adblock&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;You're losing ~ 25% of your revenue because of AdBlock, which is not negligible. If your ads are not unpleasant or harassing, you do not have a fake button leading to advertising, or pop-up windows, &lt;em&gt;IN MY OPINION&lt;/em&gt; you have the right to fight AdBlock.&lt;/p&gt;

&lt;h1&gt;
  
  
  But how?
&lt;/h1&gt;

&lt;p&gt;The aim of this article is to help you, as a website owner, to combat advertising blocking. To win, you need to understand how AdBlock works. Identify its strengths and weaknesses and set a strategy against blocking advertising accordingly.&lt;/p&gt;

&lt;h1&gt;
  
  
  What AdBlock is?
&lt;/h1&gt;

&lt;p&gt;AdBlock is primarily referred to as web browser add-ons that block ads on websites. The user simply installs them into the web browser and no longer has to worry about anything when browsing through the Internet. AdBlock will solve everything in the background.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What and how it is blocked?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;So how can AdBlock find advertising and just not show it to the user? To find the answer, at least have basic knowledge of HTML and CSS. Let's have the following HTML structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"article"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  This is an article.
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"advertisement"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; 
  Buy new phone with 50% discount!
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"article_2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  Another article.
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;On a glance, it's clear what advertising is, and what an advertiser isn't. The AdBlock add-on just looks at its database of well-known ads and compares the individual elements on the page. If it finds a match, it removes the element from the page. Since &lt;code&gt;id = "Advertisement"&lt;/code&gt; is most likely in the database of known ads, AdBlock deletes this element and all its children in HTML.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;What's AdBlock targeting?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;AdBlock can write rules on anything in HTML and CSS. It can focus on the level of HTML tag immersion, their classes, id, attribute data, css rules and their order.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;How to find out what AdBlock is catching on my page?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you don't know what AdBlock is grasping for on your page, I attach a simple guide.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install AdBlock Plus as a add-on to your browser,&lt;/li&gt;
&lt;li&gt;open DevTools (F12 keyboard shortcut),&lt;/li&gt;
&lt;li&gt;in DevTools, click on the "AdBlock Plus" tab,&lt;/li&gt;
&lt;li&gt;up in dropdown, set up "Show _ Blocked _ Items of _ any _ type",&lt;/li&gt;
&lt;li&gt;Reload Page&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You'll get a red sheet of all the blocked elements on the page, their types (script, element, etc.), domains and blocking rules. You can read from it what easlist the rule comes from.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Program for &lt;em&gt;"acceptable ads"&lt;/em&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The first ways is an official one. AdBlock Plus has a &lt;a href="https://adblockplus.org/en/acceptable-ads"&gt;program&lt;/a&gt; for &lt;em&gt;"acceptable ads"&lt;/em&gt; that grants an exception with blocking advertising under certain conditions.&lt;/p&gt;

&lt;p&gt;Conditions include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Placing advertising outside the main content&lt;/li&gt;
&lt;li&gt;Clear resolution of what is content and what is advertising&lt;/li&gt;
&lt;li&gt;Advertising size on the page&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Create issue in easylist to remove rule&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If you think AdBlock is blocking an element that isn't advertising, or a rule on your page breaks a layout, you can add an issue to the appropriate easylist with a comment on what's blocking, what's breaking it, and how to reproduce it. If the easylist administrator approves your claim, the rule will be removed or replaced.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Proxy URLs&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Proxing a familiar advertising URL through your domain. AdBlock can focus on URLs in the link in HTML (for example, &lt;code&gt;advertima.eshop.com/mobile&lt;/code&gt;), thereby blocking the entire advertising element. So if you change the URL in the link to, for example, &lt;code&gt;yourdomain.com/direct?ID=3958104&lt;/code&gt; and redirect from this URL to &lt;code&gt;advertima.eshop.com/mobile&lt;/code&gt;, AdBlock has nothing to grab on to.&lt;/p&gt;

&lt;p&gt;Advertising scripts that AdBlock simply blocks can also be tackled this way.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Hashing CSS classes and attributes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;The often used technique of fighting AdBlock is hashing out CSS classes and other elements. If a CSS ad has a class called &lt;code&gt;Ad&lt;/code&gt;, it's simple to filter it out. If you're throwing up the value, filtering it will be more native. If you dynamically hash out the value, filtering using CSS classes will be virtually impossible.&lt;/p&gt;

&lt;p&gt;Such dynamic shedding can have different implemnnings. For example, you can use a bundler (e.g. &lt;a href="https://webpack.js.org/"&gt;Webpack&lt;/a&gt;, together with &lt;a href="https://webpack.js.org/loaders/css-loader/#modules"&gt;CSS Modules&lt;/a&gt;), which classes use the hashing feature to execute such as &lt;em&gt;class name&lt;/em&gt; + &lt;em&gt;git commit hash&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Advertising camouflage&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Another problem with advertising as such is its uniqueness and simple filtering. So how do you disguise such advertising?&lt;/p&gt;

&lt;p&gt;Add other non-promotional elements to the page that have the same HTML structure, but different content. Such an element is more challenging not to include in the filtering rule.&lt;/p&gt;

&lt;p&gt;If AdBlock adds a rule that blocks both advertising and the non-advertising element, you can go back a few steps above and create an issue in the relevant easylist.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Using SVG instead of text "Advertising"&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;You may be required to label the advertising element with the words "Advertising" or "Sponsored." Unfortunately, that play into the hands of AdBlock.&lt;/p&gt;

&lt;p&gt;It's easy to get around. Instead of text as such, you display SVG, which contains the text in question and insert it as a background image. The text in the SVG thus embedded is hidden for AdBlock. When you combine this approach with hashing out the URL of a given SVG, you have a solid defense.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"100"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"35"&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;"http://www.w3.org/2000/svg"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;g&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rect&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"none"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"37"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"102"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;g&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;text&lt;/span&gt; &lt;span class="na"&gt;font-family=&lt;/span&gt;&lt;span class="s"&gt;"Helvetica, Arial, sans-serif"&lt;/span&gt; &lt;span class="na"&gt;font-size=&lt;/span&gt;&lt;span class="s"&gt;"24"&lt;/span&gt; &lt;span class="na"&gt;y=&lt;/span&gt;&lt;span class="s"&gt;"24.5"&lt;/span&gt; &lt;span class="na"&gt;x=&lt;/span&gt;&lt;span class="s"&gt;"2.5"&lt;/span&gt; &lt;span class="na"&gt;stroke-width=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt; &lt;span class="na"&gt;stroke=&lt;/span&gt;&lt;span class="s"&gt;"#000"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"#444"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      Advertising
    &lt;span class="nt"&gt;&amp;lt;/text&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/g&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To meet the previous &lt;em&gt;Advertising&lt;/em&gt; point, you can create a second SVG that has no text and is zero in size. You insert such SVGs into all non-advertising elements so that, again, they are least different from advertising in terms of HTML structure.&lt;/p&gt;

&lt;p&gt;Another approach is to parse texts into several HTML tags in different order. Facebook, for example, has implemented this approach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uj6gsX_9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s6lqjj8krejv8stqyosc.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uj6gsX_9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/s6lqjj8krejv8stqyosc.jpeg" alt="Facebook's strategy to fight AdBlock"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Full article is accessible on my Gastby blog &lt;a href="http://bit.ly/bypass-adblock"&gt;http://bit.ly/bypass-adblock&lt;/a&gt;&lt;/p&gt;

</description>
      <category>adblock</category>
    </item>
  </channel>
</rss>
