<?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: Domagoj Vidovic</title>
    <description>The latest articles on DEV Community by Domagoj Vidovic (@domagojvidovic).</description>
    <link>https://dev.to/domagojvidovic</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%2F638063%2F50291ce7-4b04-4fb2-9345-78c9ab113451.png</url>
      <title>DEV Community: Domagoj Vidovic</title>
      <link>https://dev.to/domagojvidovic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/domagojvidovic"/>
    <language>en</language>
    <item>
      <title>Don’t Use Margins For Spacing Between Components, Use Gaps</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Tue, 07 Dec 2021 15:24:44 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/dont-use-margins-for-spacing-between-components-use-gaps-4llc</link>
      <guid>https://dev.to/domagojvidovic/dont-use-margins-for-spacing-between-components-use-gaps-4llc</guid>
      <description>&lt;p&gt;The layout is hard.&lt;/p&gt;

&lt;p&gt;There are many different CSS/HTML approaches these days, but most of them are wrong.&lt;/p&gt;

&lt;p&gt;"I need to create vertical spacing between components; should I use margins or paddings?"&lt;/p&gt;

&lt;p&gt;None.&lt;/p&gt;

&lt;p&gt;Let's dive deeper into the organisation of your components on the screen.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Fall Of Margins
&lt;/h2&gt;

&lt;p&gt;In prehistoric Web times when we had linked documents instead of reusable components, margins made a lot of sense. Let's face it, there wasn't a lot of choices.&lt;/p&gt;

&lt;p&gt;Today, in an ideal situation, your Web App should be composed out of reusable components, all the time.&lt;/p&gt;

&lt;p&gt;You should be able to pick a component, plug it somewhere in the UI, and it should "magically" work, without any additional styling.&lt;/p&gt;

&lt;p&gt;If your layout is set up correctly, mobile design should work out of the box too!&lt;/p&gt;

&lt;p&gt;Margins are not great here. Obviously, you can get the job done, but it takes far more effort. It's way less elegant, and harder to maintain.&lt;/p&gt;




&lt;p&gt;So, how should we add spacing between those components?&lt;/p&gt;

&lt;p&gt;We can just pass margin as a prop, right?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No.&lt;/strong&gt; Components shouldn't care about spacing between them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Their parents should.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Adding Some Gap
&lt;/h2&gt;

&lt;p&gt;Our layout can be magical and powerful with &lt;code&gt;flex&lt;/code&gt; and &lt;code&gt;grid&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's say we have multiple components and want to have 3 in each row. Also, spacing between them should be &lt;code&gt;1rem&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Components don't care about that. Only the parent does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.parent&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;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1rem&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 that it! Whichever component we stick here, it will magically work (if we don't have a large &lt;code&gt;min-width&lt;/code&gt; set on them).&lt;/p&gt;

&lt;p&gt;What about tablet and mobile designs? The tablet should display 2 items per row, and mobile just 1.&lt;/p&gt;

&lt;p&gt;Well, we just need to add 2 different media queries; one with &lt;code&gt;grid-template-columns: 1fr 1fr;&lt;/code&gt; for tablet, and &lt;code&gt;grid-template-columns: 1fr;&lt;/code&gt; for mobile.&lt;/p&gt;

&lt;p&gt;And our layout will work all the time with just a few simple lines!&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gap&lt;/code&gt; is a replacement for all various combinations of parent + child selectors and &lt;code&gt;margin&lt;/code&gt; &lt;code&gt;top&lt;/code&gt;/&lt;code&gt;right&lt;/code&gt;/&lt;code&gt;bottom&lt;/code&gt;/&lt;code&gt;left&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  When To Use Margins?
&lt;/h2&gt;

&lt;p&gt;We don't want to make unnecessary wrappers for all of our elements, and many of them need spacing between. What should we do?&lt;/p&gt;

&lt;p&gt;If you style pure HTML elements, margins are acceptable here.&lt;/p&gt;

&lt;p&gt;I still encourage you to structure them with grid/flex and use gap, but sometimes it's just not so easy to do that without adding additional wrapper elements.&lt;/p&gt;

&lt;p&gt;So, this should be enough to make a decision:&lt;/p&gt;

&lt;p&gt;Can you add spacing without adding extra elements, with grid/flex + gap?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If yes, do it.&lt;/li&gt;
&lt;li&gt;If not, use margins.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember, this is true only for pure HTML elements. You never want to have margins on your components. A parent should always take care of their positioning on the screen. &lt;code&gt;grid&lt;/code&gt;/&lt;code&gt;flex&lt;/code&gt; + &lt;code&gt;gap&lt;/code&gt; is the most elegant and powerful option here.&lt;/p&gt;




&lt;p&gt;Also, a valid use case is when the spacing between the components is different. Selecting a child component in a &lt;code&gt;.parent .child {}&lt;/code&gt; format and adding a margin makes a lot of sense.&lt;/p&gt;

&lt;p&gt;But if you have too many different spacings, you need to ask yourself - is there a problem with the design itself?&lt;/p&gt;




&lt;h2&gt;
  
  
  Pros and Cons
&lt;/h2&gt;

&lt;p&gt;Let's take a look at the pros first.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Your overall architecture will be much cleaner.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;grid&lt;/code&gt; and &lt;code&gt;flex&lt;/code&gt; are powerful. All scenarios like element wrapping, overflow, and much more will be covered.&lt;/li&gt;
&lt;li&gt;Responsive design works out of the box. It's so easy when you don't need to switch from margin-left to margin-top for mobile layouts.&lt;/li&gt;
&lt;li&gt;Instead of calculating the position of every element relative to each other, the parent will always do it with a clear picture of a whole system.&lt;/li&gt;
&lt;li&gt;Your CSS will be much cleaner. You won't need those ugly classes where you target everything instead of the last element because you don't want to add margin-bottom to the last item in the list.&lt;/li&gt;
&lt;li&gt;Your components will be completely reusable because they won't have any spacing by default.&lt;/li&gt;
&lt;li&gt;This whole system will be way easier to maintain and extend.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's kinda like the &lt;strong&gt;plug and play system&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;With margins, it's the plug, &lt;strong&gt;adjust&lt;/strong&gt;, and then play system.&lt;/p&gt;

&lt;p&gt;We don't want that extra adjustment step.&lt;/p&gt;




&lt;p&gt;Are there any cons? Well, both yes and no. The only one I can think of is &lt;code&gt;gap&lt;/code&gt; not supported by IE11.&lt;/p&gt;

&lt;p&gt;But you know what? Google search has dropped support for IE11. And you should too.&lt;/p&gt;

&lt;p&gt;Let your layout become something you're so proud of. We're building a system of components here and &lt;code&gt;gap&lt;/code&gt; is just perfect for it.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>tutorial</category>
      <category>css</category>
      <category>html</category>
    </item>
    <item>
      <title>How To Create Beautiful Link Previews For Every Platform</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 08 Nov 2021 17:05:42 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/how-to-create-beautiful-link-previews-for-every-platform-1nka</link>
      <guid>https://dev.to/domagojvidovic/how-to-create-beautiful-link-previews-for-every-platform-1nka</guid>
      <description>&lt;p&gt;You've been working hard on your web app.&lt;/p&gt;

&lt;p&gt;It's finally done. You are proud of it and want to share it.&lt;/p&gt;

&lt;p&gt;But after pasting a link to Twitter, your link preview is so broken. Only the title is correct, everything else is missing.&lt;/p&gt;

&lt;p&gt;The first impression everyone will have about your app — is bad.&lt;/p&gt;

&lt;p&gt;Let's fix that.&lt;/p&gt;

&lt;p&gt;After reading this article, you will be able to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Have a correct image, title, and description.&lt;/li&gt;
&lt;li&gt;Make it work properly on all platforms.&lt;/li&gt;
&lt;li&gt;Have different previews depending on the shared page.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And it's all so simple.&lt;/p&gt;




&lt;h2&gt;
  
  
  Mystical Meta Tags
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags in your HTML files have many use cases — one of them is to set up preview data properly.&lt;/p&gt;

&lt;p&gt;There are eight most common attributes you need to set to make it look properly in 99% of the cases:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;code&gt;title&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;description&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;og:title&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;og:description&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;og:image&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;twitter:title&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;twitter:description&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;twitter:image&lt;/code&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If &lt;code&gt;twitter&lt;/code&gt; is missing, it will fall back to &lt;code&gt;og&lt;/code&gt;; but still, it's great to include it.&lt;/p&gt;

&lt;p&gt;First, you need to set up the correct meta tags in your &lt;code&gt;index.html&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Your Title&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:title"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your Title"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"twitter:title"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your Title"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your Description"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your Description"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"twitter:description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Your Description"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;property=&lt;/span&gt;&lt;span class="s"&gt;"og:image"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"img_url"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"twitter:image"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"img_url"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, you'll have the correct previews when you share your page.&lt;/p&gt;

&lt;p&gt;But what if you want different previews for different pages?&lt;/p&gt;




&lt;h2&gt;
  
  
  Updating The Meta Tags
&lt;/h2&gt;

&lt;p&gt;Updating meta tags is a straightforward process. You can use external libs for that (e.g. React Helmet if you use React), but I'll share my own pure JS solution.&lt;/p&gt;

&lt;p&gt;Let's say we want to update the title. This code does exactly that:&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;// update og:title&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[property="og:title"]&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;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;yourTitle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// update twitter:title&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name="twitter:title"]&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;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;yourTitle&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// update the "regular" title&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;yourTitle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's quite similar for description and image.&lt;/p&gt;

&lt;p&gt;But we don't want to use it in this way. Let's create some helper functions!&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="nx"&gt;setTitle&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="p"&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;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;yourTitle&lt;/span&gt;&lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[property="og:title"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name="twitter:title"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&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="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name="description"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[property="og:description"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name="twitter:description"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;setImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[property="og:image"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;image&lt;/span&gt;&lt;span class="p"&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;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name="twitter:image"]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;setAttribute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;content&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;image&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;It's that simple.&lt;/p&gt;

&lt;p&gt;Ideally, you can create a helper setMetadata and call it after your page gets mounted:&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="nx"&gt;setMetadata&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;setTitle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;metadata&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;setDescription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;setImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&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;But there is one trick.&lt;/p&gt;

&lt;p&gt;This won't work properly because the metadata is updated on the client. Meaning, you need to download the app first and parse and execute the JS to update the meta tags.&lt;/p&gt;

&lt;p&gt;You might think that you need to set up a separate server to have correct previews for the different pages. Luckily, you don't have to!&lt;/p&gt;

&lt;p&gt;There is a simple solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's Prerender
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://prerender.io/"&gt;Prerender.io&lt;/a&gt; is an amazing tool that will simulate serving a static HTML page to the crawlers.&lt;/p&gt;

&lt;p&gt;So, instead of just improving your preview links, this will also boost your SEO. Woohoo!&lt;/p&gt;

&lt;p&gt;The process is simple.&lt;/p&gt;

&lt;p&gt;First, you need to create an account there (it's free!).&lt;/p&gt;

&lt;p&gt;Then install &lt;a href="https://github.com/prerender/prerender-node"&gt;prerender-node&lt;/a&gt; package.&lt;/p&gt;

&lt;p&gt;They have nice docs, but the only thing you'll probably need to do is add this line to your express app (probably to your &lt;code&gt;server.js&lt;/code&gt; file):&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prerender-node&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="kd"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;prerenderToken&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="s1"&gt;YOUR_TOKEN&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;You can get &lt;code&gt;'YOUR_TOKEN'&lt;/code&gt; from prerender.io after you register.&lt;/p&gt;

&lt;p&gt;Commit your changes, deploy them, and you're ready to go!&lt;/p&gt;




&lt;h2&gt;
  
  
  Making Sure It Works Properly
&lt;/h2&gt;

&lt;p&gt;You can paste your link to all the platforms and check it manually, but there are much better tools for that. For example, &lt;a href="https://socialsharepreview.com/"&gt;Social Share Preview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Just paste your URL there and see the preview. If you missed something, the tool would let you know what you're missing.&lt;/p&gt;

&lt;p&gt;There are many other tools that do the same trick, google them if this isn't enough for you.&lt;/p&gt;




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

&lt;p&gt;You have it now; your preview links look beautiful on all the platforms!&lt;/p&gt;

&lt;p&gt;I just wanted to add that you might have some specific use cases not covered with this tutorial. It's all fine — just google the problem and find a specific meta tag you need. Then, update it with pure JS.&lt;/p&gt;

&lt;p&gt;Happy previewing!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;a href="https://domagojvidovic.com/post/how-to-create-beautiful-link-previews-for-every-platform"&gt;This post was originally published on Dom's personal blog. Check out dat new amazing blog design there ✨&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Set Up Blazing Fast Frontend Development Experience With Vite</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 01 Nov 2021 15:34:36 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/set-up-blazing-fast-frontend-development-experience-with-vite-1b7k</link>
      <guid>https://dev.to/domagojvidovic/set-up-blazing-fast-frontend-development-experience-with-vite-1b7k</guid>
      <description>&lt;p&gt;Your production app is huge.&lt;/p&gt;

&lt;p&gt;You hit &lt;code&gt;npm run dev&lt;/code&gt; to start your development server.&lt;/p&gt;

&lt;p&gt;After 1 minute, it's there! You can start your dev journey.&lt;/p&gt;

&lt;p&gt;Although 1 minute doesn't seem like a long time  —  for us devs, it is. We are nitpicky and want everything &lt;strong&gt;instantly&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Luckily, there's a brand new tool that allows us that.&lt;/p&gt;

&lt;p&gt;I present you  —  &lt;a href="https://vitejs.dev/"&gt;Vite&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  What is Vite?
&lt;/h2&gt;

&lt;p&gt;Vite is a build tool that provides a blazing fast development experience.&lt;/p&gt;

&lt;p&gt;Vite is a french word for "quick", and it's pronounced &lt;code&gt;/vit/&lt;/code&gt; (not white!).&lt;/p&gt;

&lt;p&gt;It's created by Evan You, the same guy who created Vue.js.&lt;/p&gt;

&lt;p&gt;That doesn't mean that Vite is only for Vue.js  —  it's framework agnostic!&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Is It So Fast?
&lt;/h2&gt;

&lt;p&gt;If you don't care about this and just want to set up Vite, just skip this section.&lt;/p&gt;




&lt;p&gt;If you're still with me, amazing! I have a few history lessons for you.&lt;/p&gt;

&lt;p&gt;Webpack, the most popular build tool today, was released in 2014.&lt;/p&gt;

&lt;p&gt;Back then, browsers didn't support native module imports, so bundling the files made sense.&lt;/p&gt;

&lt;p&gt;Not anymore in 2021.&lt;/p&gt;

&lt;p&gt;It's an expensive process.&lt;/p&gt;

&lt;p&gt;Plus, every time you update a single file, you need to update the whole bundle to see the change on the screen.&lt;/p&gt;

&lt;p&gt;That's why Hot Module Reload can sometimes take many seconds!&lt;/p&gt;

&lt;p&gt;Vite uses the power of native module imports, making your Hot Module Reload instant.&lt;/p&gt;

&lt;p&gt;There are still some deeper reasons why it is so fast, so if you're interested, check out their website. But now, let's set up the app!&lt;/p&gt;




&lt;h2&gt;
  
  
  Setting Up Vite… Is Simple And Fast As It Sounds
&lt;/h2&gt;

&lt;p&gt;There's only one prerequisite: &lt;code&gt;Node version &amp;gt;=12.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After it, you're all good!&lt;/p&gt;

&lt;p&gt;Open your terminal and type:&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="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="nx"&gt;vite&lt;/span&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;latest&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, you have steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Project name&lt;/li&gt;
&lt;li&gt;Framework (Vanilla JS, Vue, React, Preact, Lit, Svelte)&lt;/li&gt;
&lt;li&gt;Typescript or pure JS&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that's it!&lt;/p&gt;

&lt;p&gt;Now, you need to go to your project folder:&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="nx"&gt;cd&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;YOUR_PROJECT_NAME&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install the dependencies:&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="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And start the development server:&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="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;run&lt;/span&gt; &lt;span class="nx"&gt;dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's what happens next:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FoOs4PHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vupmydplpqt3ehligkil.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FoOs4PHc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vupmydplpqt3ehligkil.png" alt="Blazing fast Vite" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's ready in less than 0.3 seconds. That's insane!&lt;/p&gt;

&lt;p&gt;Just for a comparison, the same app made with VueCLI + Webpack takes 10s initially. This makes Vite &lt;strong&gt;39x faster&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;I won't even talk about the speed after the app gets bigger.&lt;/p&gt;




&lt;p&gt;And Hot Module Reload is  —  instant.&lt;/p&gt;

&lt;p&gt;Webpack takes around 2–3 seconds (initially), and up to 5 seconds for massive apps.&lt;/p&gt;




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

&lt;p&gt;What do you think about Vite?&lt;/p&gt;

&lt;p&gt;New Frontend tools come out every day, but I can't remember when was I excited as this. I believe this could radically improve our already great Frontend development experience.&lt;/p&gt;

&lt;p&gt;Have you tried it yet?&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;a href="https://domagojvidovic.com/post/set-up-blazing-fast-frontend-development-experience-with-vite"&gt;This post was originally published on Dom's personal blog. Check out dat new amazing blog design there ✨&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webpack</category>
    </item>
    <item>
      <title>Position Absolute and Relative  — The Simplest Guide</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 25 Oct 2021 14:51:45 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/position-absolute-and-relative-the-simplest-guide-5169</link>
      <guid>https://dev.to/domagojvidovic/position-absolute-and-relative-the-simplest-guide-5169</guid>
      <description>&lt;p&gt;I remember the time when I was starting my Frontend journey.&lt;/p&gt;

&lt;p&gt;CSS caused a lot of headaches. Like most people, I assumed that it's easy. Then, I was annoyed when I couldn't get it working.&lt;/p&gt;

&lt;p&gt;My usual flow was:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Detect a problem.&lt;/li&gt;
&lt;li&gt;Google it.&lt;/li&gt;
&lt;li&gt;Find a solution on StackOverflow.&lt;/li&gt;
&lt;li&gt;C/P it without any understanding.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Position absolute and relative were properties I often encountered. "What the heck are they?"&lt;/p&gt;

&lt;p&gt;They should be used far less often than you might use them, and when used properly, they are quite simple.&lt;/p&gt;

&lt;p&gt;Let's dive deeper into the topic.&lt;/p&gt;




&lt;h2&gt;
  
  
  How Are Position Absolute and Relative Related?
&lt;/h2&gt;

&lt;p&gt;Usually, all elements follow the DOM flow. &lt;/p&gt;

&lt;p&gt;But sometimes, you need to break that flow and tell an element exactly where to go.&lt;/p&gt;

&lt;p&gt;Let's say that I have this HTML page:&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%2Fuploads%2Farticles%2Flcwvzstgiyalh0bs3r76.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%2Fuploads%2Farticles%2Flcwvzstgiyalh0bs3r76.png" alt="HTML Page"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code is quite simple:&lt;/p&gt;

&lt;div class="highlight js-code-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;class=&lt;/span&gt;&lt;span class="s"&gt;"bordered-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"absolute-item"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nt"&gt;body&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;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;linear-gradient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;span class="m"&gt;90deg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;153&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;253&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;103&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;0%&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;88&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;255&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;228&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.bordered-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&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;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.absolute-item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-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;I want to absolutely position my &lt;code&gt;absolute-item&lt;/code&gt; right now and tell it exactly where to be. I want it to be always inside the &lt;code&gt;bordered-container&lt;/code&gt;; &lt;code&gt;10px&lt;/code&gt; away from the bottom, and &lt;code&gt;30px&lt;/code&gt; from the right.&lt;/p&gt;

&lt;p&gt;Let's add the code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.absolute-item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;30px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;40px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;background-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;The result is:&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%2Fuploads%2Farticles%2Fq8xx7nibv33eeavqaoji.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%2Fuploads%2Farticles%2Fq8xx7nibv33eeavqaoji.png" alt="Position absolute"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It's, obviously, not what we wanted. The square is positioned &lt;code&gt;10px&lt;/code&gt;/&lt;code&gt;30px&lt;/code&gt; away from the edge of a whole document, not the &lt;code&gt;bordered-container&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;That's why we need &lt;code&gt;position: relative;&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  It's Not Black Magic
&lt;/h2&gt;

&lt;p&gt;Whenever you set &lt;code&gt;position: absolute;&lt;/code&gt; to an element, it must be positioned &lt;strong&gt;relative&lt;/strong&gt; to something.&lt;/p&gt;

&lt;p&gt;Your absolute element will look for the closest parent with &lt;code&gt;position: relative;&lt;/code&gt;, and position itself relative to it.&lt;/p&gt;

&lt;p&gt;If there are no elements like that, it will be positioned relative to the &lt;code&gt;body&lt;/code&gt; element. This happened in our previous case.&lt;/p&gt;

&lt;p&gt;To fix this, we simply need to add &lt;code&gt;position: relative;&lt;/code&gt; to our &lt;code&gt;bordered-container&lt;/code&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;

&lt;span class="nc"&gt;.bordered-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;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="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300px&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;2px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="no"&gt;black&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;The result is:&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%2Fuploads%2Farticles%2F9ce14ftotzbqrn1y2hz5.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%2Fuploads%2Farticles%2F9ce14ftotzbqrn1y2hz5.png" alt="Absolutely positioned item"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yep, it's that simple.&lt;/p&gt;




&lt;h2&gt;
  
  
  What The Heck Is Z-Index?
&lt;/h2&gt;

&lt;p&gt;When dealing with absolute positions, you might encounter on z-index, so it's worth mentioning.&lt;/p&gt;

&lt;p&gt;I'm sure that you've tried setting it to &lt;code&gt;9999&lt;/code&gt; but it still didn't work.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;z-index&lt;/code&gt; is used when you have multiple absolute position elements.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;absolute positioned&lt;/strong&gt; element with the biggest &lt;code&gt;z-index&lt;/code&gt; will go on the top. The one with the lowest, on the bottom. &lt;/p&gt;

&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;Let's keep it simple.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Downsides Of Position Absolute
&lt;/h2&gt;

&lt;p&gt;Absolutely positioned elements break the DOM flow. &lt;/p&gt;

&lt;p&gt;They don't take any physical space on the document.&lt;/p&gt;

&lt;p&gt;That means that the elements above/below could overlap with, even if you don't want it.&lt;/p&gt;

&lt;p&gt;This can become tricky to maintain. &lt;/p&gt;

&lt;p&gt;Our elements should be isolated, if we change one of them, we don't want to adjust everything else.&lt;/p&gt;

&lt;p&gt;That doesn't mean &lt;code&gt;position: absolute;&lt;/code&gt; is bad! It means that it has its own use cases and you need to know about them.&lt;/p&gt;




&lt;h2&gt;
  
  
  When To Use It
&lt;/h2&gt;

&lt;p&gt;If you need to adjust the layout within a page or a component, you should avoid &lt;code&gt;position: absolute;&lt;/code&gt; in 99% of the cases. Opt-in for Flexbox or Grid instead.&lt;/p&gt;

&lt;p&gt;However, if you want to add a badge to your image, it's just perfect. You always want the badge to be on the top (or the edge) of the image, so that it seems like it's a part of an image.&lt;/p&gt;

&lt;p&gt;Or if you want to stack a few images/elements onto each other. There's no way other than &lt;code&gt;position: absolute;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And that's the ultimate guide: &lt;strong&gt;use absolute positioning only when there's no other way to achieve that&lt;/strong&gt;.&lt;/p&gt;




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

&lt;p&gt;Absolute positioning is powerful, and the Web wouldn't be able to look this way without it.&lt;/p&gt;

&lt;p&gt;If used properly, it's a charm.&lt;/p&gt;

&lt;p&gt;But those use cases are quite rare. If you use it often, you will make your app a hell to maintain.&lt;/p&gt;

&lt;p&gt;If you find a StackOverflow answer with &lt;code&gt;position: absolute;&lt;/code&gt;, try to skip it. Keep looking. Is there any other way to do it?&lt;/p&gt;

&lt;p&gt;If so, avoid the &lt;code&gt;absolute&lt;/code&gt;.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;&lt;a href="https://domagojvidovic.com/post/position-absolute-relative-the-simplest-guide" rel="noopener noreferrer"&gt;This post was originally published on Dom's personal blog. Check out dat new amazing blog design there ✨&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>11 Reasons Why Software Engineering Isn’t a Stressful Job</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Tue, 14 Sep 2021 15:19:30 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/11-reasons-why-software-engineering-isn-t-a-stressful-job-57ak</link>
      <guid>https://dev.to/domagojvidovic/11-reasons-why-software-engineering-isn-t-a-stressful-job-57ak</guid>
      <description>&lt;p&gt;Everyone talks tech these days.&lt;/p&gt;

&lt;p&gt;Software engineers are being raised to the skies in terms of their abilities and work complexities.&lt;/p&gt;

&lt;p&gt;But sometimes, it feels like we forget about all the other professions. We ignore their difficulties by focusing on our own.&lt;/p&gt;

&lt;p&gt;Instead of that, let’s focus on the positive sides and acknowledge that our job isn’t stressful.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. We can prioritize time
&lt;/h2&gt;

&lt;p&gt;A major cause of stress is uncertainty. If you don’t know you’ve worked well or done enough work, you could be stressed.&lt;/p&gt;

&lt;p&gt;I don’t know the processes inside your company, but it’s highly likely that you set your bi-weekly/weekly/daily priorities for everyone.&lt;/p&gt;

&lt;p&gt;That’s said, you know exactly what you should work on. Thereby, you can prioritize it.&lt;/p&gt;

&lt;p&gt;When I was starting my career, I didn’t know how much is enough. OK, so I did 4 tasks today; should have I done 6 of them?&lt;/p&gt;

&lt;p&gt;Those questions caused stress.&lt;/p&gt;

&lt;p&gt;Today, I plan my work in the morning before I start with anything.&lt;/p&gt;

&lt;p&gt;When I’m done with it — I’m done! I often grab something else to do, but I’m not stressed about it. I know that I did everything I should have.&lt;/p&gt;

&lt;p&gt;On rare occasions, some extra work might pop in and disrupt our plan. You need to learn to adapt it too, and not care about the overhead.&lt;/p&gt;

&lt;p&gt;We are almost completely in control of our day-to-day work; we can put it on paper and schedule it.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The demand for us is ridiculously high
&lt;/h2&gt;

&lt;p&gt;You can be stressed because you don’t like your job. Or, you might think that you’ll get fired.&lt;/p&gt;

&lt;p&gt;But become aware: everyone needs software engineers.&lt;/p&gt;

&lt;p&gt;We need to build this invisible world and there are no limits. We’ve just started.&lt;/p&gt;

&lt;p&gt;On a typical week, I receive ~10 email/LinkedIn messages from recruiters, with the best offers on the market.&lt;/p&gt;

&lt;p&gt;That means that we can go wherever we want, do whatever we like. There are so many options, and everyone’s grabbing for us.&lt;/p&gt;

&lt;p&gt;There’s not enough of us, we’re exclusive.&lt;/p&gt;

&lt;p&gt;We know that we’ll do well, all the time.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Flexibility is underrated
&lt;/h2&gt;

&lt;p&gt;My company offers a free subscription to the co-working spaces in London. Some of those locations are the best in the whole city.&lt;/p&gt;

&lt;p&gt;Because of it, I worked at The Shard yesterday, London’s highest skyscraper.&lt;/p&gt;

&lt;p&gt;Last week, I was in Croatia, working remotely from the beach.&lt;/p&gt;

&lt;p&gt;Today, I’ll work from home and go to the rooftop at some point because the weather is so nice.&lt;/p&gt;

&lt;p&gt;And on Thursday, I’ll go to the office because everyone will be there and we’ll have drinks after.&lt;br&gt;
We can do whatever we want. The only important thing is to finish your work. If you bring value, nobody cares where you are or when you started.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Work-life balance just rocks
&lt;/h2&gt;

&lt;p&gt;Let’s face it — Software Engineering is a highly paid job. Sometimes it’s right on par with Lawyers, Doctors, and Investment Bankers.&lt;/p&gt;

&lt;p&gt;However, those guys can sometimes have crazy working hours; 80 per week and even more. And I haven’t even mentioned the night shifts.&lt;/p&gt;

&lt;p&gt;What about us?&lt;/p&gt;

&lt;p&gt;Well, after our 8 hours, we can go wherever we want — especially if we did everything we needed.&lt;/p&gt;

&lt;p&gt;Sure, sometimes deadlines force you to work a bit more — but it’s nothing compared to the other highly paid professions.&lt;/p&gt;

&lt;p&gt;Even the low-paid ones have a much worse working balance.&lt;/p&gt;

&lt;p&gt;Again, we’re in a sweet spot.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Everyone is just joking around
&lt;/h2&gt;

&lt;p&gt;I’ve been working with 5 different companies so far — and all of them were having fun all the time while working.&lt;/p&gt;

&lt;p&gt;Sure, there are some serious moments, but most of the time it’s just laughing, making jokes, sending random images, GIFs, and reactions on Slack.&lt;/p&gt;

&lt;p&gt;Not that we don’t work — we’re incredibly efficient. However, we feel better this way and enjoy our work more; that way, we work even better.&lt;/p&gt;

&lt;p&gt;And how about those random beers during work hours, or meetings that turn out to the joke warehouse? All of our socials?&lt;/p&gt;

&lt;p&gt;I sometimes feel like we’re all just smart children — doing great work and laughing all the time.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. All of our problems are solved online
&lt;/h2&gt;

&lt;p&gt;The community we live in is incredible.&lt;/p&gt;

&lt;p&gt;Need to build something? Google it.&lt;/p&gt;

&lt;p&gt;Have an error? Paste it to Google.&lt;/p&gt;

&lt;p&gt;Can’t find the answer? Ask it on StackOverflow.&lt;/p&gt;

&lt;p&gt;Finding the right solution is a valuable skill. But we have that option. We can find help anywhere.&lt;/p&gt;

&lt;p&gt;Even if we can’t do it online, we’ll ask our team members for it.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. The best tools are free
&lt;/h2&gt;

&lt;p&gt;Our friends from other professions have to pay crazy subscriptions to use some tools. It can be $10k+ per person, just to use something that we created!&lt;/p&gt;

&lt;p&gt;I’m a Frontend Engineer; let’s see how much I need to pay for my tools.&lt;/p&gt;

&lt;p&gt;VS Code? Free.&lt;/p&gt;

&lt;p&gt;Vue/React/Angular/Svelte? Free.&lt;/p&gt;

&lt;p&gt;JavaScript/HTML/CSS? Free.&lt;/p&gt;

&lt;p&gt;Git? Free.&lt;/p&gt;

&lt;p&gt;Powerful extensions? Free.&lt;/p&gt;

&lt;p&gt;Let’s face it, almost everything’s free.&lt;/p&gt;

&lt;p&gt;We obviously need to pay for hosting services like AWS, but almost everything until that point is free.&lt;/p&gt;

&lt;p&gt;We can experiment as much as we want and create prototypes with zero expenses.&lt;/p&gt;

&lt;p&gt;Ask other, non-CS engineers how costly their prototypes are.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Our equipment is so cheap and light
&lt;/h2&gt;

&lt;p&gt;I’m probably an exception — I use only my MacBook Pro to work, without any external monitors, keyboards, or anything else.&lt;/p&gt;

&lt;p&gt;But let’s say I want all those things. Even with them, the cost of equipment wouldn’t go above $2000-$3000, and I’m talking about the best devices on the market.&lt;/p&gt;

&lt;p&gt;Everyone else has similar costs because everyone needs a laptop or PC. However, they need a lot more expensive subscriptions and ridiculously expensive equipment.&lt;/p&gt;

&lt;p&gt;Science, Mechanical Engineering? The costs can be $1M+ for those.&lt;/p&gt;

&lt;p&gt;And you have to be in the office to use it most of the time.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. We all speak the same language
&lt;/h2&gt;

&lt;p&gt;The best coding practices are the same across the globe.&lt;/p&gt;

&lt;p&gt;We all speak English because of resources; the code is in English itself. That’s why we don’t have any obstacles in communication.&lt;/p&gt;

&lt;p&gt;Our skills are so valuable because they can be applied anywhere. So unique, but also so general. It’s insane.&lt;/p&gt;




&lt;h2&gt;
  
  
  10. Oh, that salary
&lt;/h2&gt;

&lt;p&gt;Money is important.&lt;/p&gt;

&lt;p&gt;Most of the things you have and use right now were exchanged for money.&lt;/p&gt;

&lt;p&gt;But not only material ones; all the wonderful experiences like traveling, eating, dating, and much more.&lt;/p&gt;

&lt;p&gt;Software engineering gives us the ability to experience the world whatever we want like. We don’t have to stress about the money.&lt;/p&gt;

&lt;p&gt;I moved to London recently, one of the most expensive cities in the world, and I can live an amazing life in a top location without thinking about the costs too much.&lt;/p&gt;

&lt;p&gt;I even have enough money for investing a decent amount every month.&lt;/p&gt;

&lt;p&gt;Not only that — what about equity and bonuses? That can end up being higher than the base salary itself.&lt;/p&gt;

&lt;p&gt;Because of high compensations, banks will give us a mortgage easily. We’re their top customers! So we can easily buy ourselves homes or invest that money.&lt;/p&gt;

&lt;p&gt;Don’t forget — we earn a lot. People in their twenties will probably earn more than others ever will in their whole lives.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. We can see our impact immediately
&lt;/h2&gt;

&lt;p&gt;I create a feature, merge the code. Using the benefits of CI/CD, this feature is shipped to the customers in 1–2 hours.&lt;/p&gt;

&lt;p&gt;I can see them using it immediately! Something that I made is making others so happy!&lt;/p&gt;

&lt;p&gt;It’s motivating. It’s meaningful.&lt;/p&gt;

&lt;p&gt;Even if it’s not shipped to customers, we have a feeling that we created something every day.&lt;/p&gt;




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

&lt;p&gt;We live in amazing times. This is the gold rush of modern time.&lt;/p&gt;

&lt;p&gt;But instead of mining, you need to learn to code.&lt;br&gt;
Sure, it can be tricky. It can be hard. It can be exhausting.&lt;/p&gt;

&lt;p&gt;But most of the time, we’re just making jokes and doing great work. From anywhere in the world.&lt;/p&gt;

&lt;p&gt;Let’s face it, we don’t have too many reasons to be stressed. If we are, we need to take control over it.&lt;/p&gt;

&lt;p&gt;Because we can.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Loving my work? Feel free to &lt;a href="https://www.buymeacoffee.com/domagojvidovic"&gt;buy me a croissant&lt;/a&gt;. It's such a motivation boost. You rock.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>A Ridiculously Simple Way For Creating Responsive Web Apps</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Wed, 08 Sep 2021 14:34:15 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/a-ridiculously-simple-way-for-creating-responsive-web-apps-1f43</link>
      <guid>https://dev.to/domagojvidovic/a-ridiculously-simple-way-for-creating-responsive-web-apps-1f43</guid>
      <description>&lt;p&gt;I remember my first encounter with responsive design. Before any investigation, it seemed incredibly complex.&lt;/p&gt;

&lt;p&gt;The same app runs and behaves differently based on so many types of user devices?&lt;/p&gt;

&lt;p&gt;I have to cover all the screen sizes, from ultra-wide monitors, over laptop and tablet devices, all the way to the smartphones?&lt;/p&gt;

&lt;p&gt;Mate, that must be a nightmare.&lt;/p&gt;

&lt;p&gt;But honestly, it isn't. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Responsive design is nothing more than a bunch of &lt;code&gt;if&lt;/code&gt; statements.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's dive deeper into the topic.&lt;/p&gt;




&lt;h2&gt;
  
  
  Two Types of Design
&lt;/h2&gt;

&lt;p&gt;Depending on what you create, you have two choices:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Mobile-First Design&lt;/li&gt;
&lt;li&gt;Desktop-First Design&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Mobile-First Design means that you first design and create software for mobile devices, and then extend it to desktop devices.&lt;/p&gt;

&lt;p&gt;It assures that your core functionality will be available on a mobile device.&lt;/p&gt;

&lt;p&gt;It's easy to add more functionality on the bigger screen, but it's hard to strip away functionality and keeping the core while going to a smaller screen.&lt;/p&gt;




&lt;p&gt;According to this &lt;a href="https://www.perficient.com/insights/research-hub/mobile-vs-desktop-usage" rel="noopener noreferrer"&gt;research&lt;/a&gt;, 68.9% of websites visit came from mobile devices.&lt;/p&gt;

&lt;p&gt;If you're creating a consumer app, Mobile-First Design is likely to be your choice.&lt;/p&gt;

&lt;p&gt;Complex B2B solutions require Desktop-First Design, and sometimes don't even have a fully functioning mobile solution - they're just too complex.&lt;/p&gt;

&lt;p&gt;That's why I'll focus on Mobile-First Design in this article.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Design
&lt;/h2&gt;

&lt;p&gt;We'll keep this simple. Let's say that you have a number of items you want to display on your feed. It will look something like this:&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%2Fuploads%2Farticles%2F6wb86405qvl0ah46jo30.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%2Fuploads%2Farticles%2F6wb86405qvl0ah46jo30.png" alt="Mobile design"&gt;&lt;/a&gt;&lt;/p&gt;
Mobile design



&lt;p&gt;We have two components here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Parent component, &lt;code&gt;container&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Child components, &lt;code&gt;items&lt;/code&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If we ignore the CSS code for everything except the layout, it will look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 1&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;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 2&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;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;.container&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;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;88px&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Can you see the meta tag, &lt;code&gt;&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;It's incredibly important and there's no responsive design without it. Without it, your browser won't know the initial zoom and it will look really bad on mobile devices.&lt;/p&gt;




&lt;h2&gt;
  
  
  Doing the Magic to Make the Desktop Work
&lt;/h2&gt;

&lt;p&gt;Just joking, this is no complex magic. As I've said, just a bunch of if statements!&lt;/p&gt;

&lt;p&gt;We're trying to spread the items, keeping 3 of them in each row:&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%2Fuploads%2Farticles%2F6qtz8vetlsnyj2ttfftl.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%2Fuploads%2Farticles%2F6qtz8vetlsnyj2ttfftl.png" alt="Desktop design"&gt;&lt;/a&gt;&lt;/p&gt;
Desktop design



&lt;p&gt;The code looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 1&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;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 2&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;class=&lt;/span&gt;&lt;span class="s"&gt;"item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Item 3&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;style&amp;gt;&lt;/span&gt;
    &lt;span class="nc"&gt;.container&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;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;align-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="py"&gt;gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;.item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;88px&lt;/span&gt; &lt;span class="m"&gt;16px&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;992px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&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="nt"&gt;&amp;lt;/style&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're finally here, introducing &lt;code&gt;@media&lt;/code&gt; queries. &lt;/p&gt;

&lt;p&gt;Let's read this in a simple, already familiar way:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (screen width is bigger or equal than 992px) {
    apply styles in the same way as before
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it! Nothing more than this! The styles here will affect only screens wider than &lt;code&gt;992px&lt;/code&gt;.&lt;/p&gt;




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

&lt;p&gt;You can combine media queries with logical operators. &lt;/p&gt;

&lt;p&gt;Yep, you can do something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;min-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;768px&lt;/span&gt;&lt;span class="p"&gt;)&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;991px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;styles&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And those styles will affect everything in range from &lt;code&gt;768px&lt;/code&gt; to &lt;code&gt;991px&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Remember, this is nothing more than an if statement.&lt;/p&gt;




&lt;h2&gt;
  
  
  How to Cover All Devices
&lt;/h2&gt;

&lt;p&gt;Media queries are much more than just &lt;code&gt;min-width&lt;/code&gt; and &lt;code&gt;max-width&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can check stuff like &lt;code&gt;orientation&lt;/code&gt;, &lt;code&gt;aspect-ratio&lt;/code&gt;, and much more.&lt;/p&gt;

&lt;p&gt;You can use logical operators like &lt;code&gt;or&lt;/code&gt;, &lt;code&gt;not&lt;/code&gt;, and all the others.&lt;/p&gt;

&lt;p&gt;But to be honest, what you've read in this article is enough for an amazing and simple start.&lt;/p&gt;

&lt;p&gt;You probably won't need most of the other queries anyway. Maybe in some rare scenarios. By then, your knowledge about queries will be so powerful that complex queries will be a joke!&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Loving my work? Feel free to &lt;a href="https://www.buymeacoffee.com/domagojvidovic" rel="noopener noreferrer"&gt;buy me a croissant&lt;/a&gt;. It's an incredible boost to my motivation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Check out the bottom of &lt;a href="https://domagojvidovic.medium.com/a-ridiculously-simple-way-for-creating-responsive-web-apps-c640f9814613" rel="noopener noreferrer"&gt;the originally published article on Medium&lt;/a&gt; for the best course around responsive web.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>css</category>
      <category>html</category>
      <category>frontend</category>
    </item>
    <item>
      <title>All CSS Properties You Need to Know to Build a Website</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 23 Aug 2021 15:34:00 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/all-css-properties-you-need-to-know-to-build-a-website-3dbb</link>
      <guid>https://dev.to/domagojvidovic/all-css-properties-you-need-to-know-to-build-a-website-3dbb</guid>
      <description>&lt;p&gt;Whether you're at the beginning of your CSS journey or somewhere else, you got to admit - a number of CSS properties is massive.&lt;/p&gt;

&lt;p&gt;And it's easy to confuse yourself in that vast sea. &lt;/p&gt;

&lt;p&gt;You're copying code from StackOverflow until you find a solution that fits. But how will that scale? Why does it even work?&lt;/p&gt;

&lt;p&gt;Most of the time, you don't care about the answer. You just focus on the result.&lt;/p&gt;

&lt;p&gt;When building a website, some of the CSS properties are must-haves; yet, it's hard to recognize them. &lt;/p&gt;

&lt;p&gt;This article exists to help you solve the most common CSS problems while building a website.&lt;/p&gt;

&lt;p&gt;Let's dive into properties you cannot avoid.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. display: flex;
&lt;/h2&gt;

&lt;p&gt;Do you need to center an element?&lt;/p&gt;

&lt;p&gt;Googling that will likely offer tens of different solutions; however, you'll need only one most of the time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.your-class-name&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;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&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;code&gt;display: flex;&lt;/code&gt; will align your child elements one next to each other in a horizontal row. Tip: you can add &lt;code&gt;flex-direction: column;&lt;/code&gt; to change it to a vertical row.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;flex-direction&lt;/code&gt; determines your main axis. Default value is &lt;code&gt;row&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;justify-content: center;&lt;/code&gt; will align the items on your main axis. That means the item will be horizontally centered for our code snippet.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;align-items&lt;/code&gt; controls your cross axis, i.e. your elements are vertically centered.&lt;/p&gt;

&lt;p&gt;You can pass many attributes here, but I'll mention only one: &lt;code&gt;justify-content: space-between;&lt;/code&gt;. This will distribute the elements across the row without any margins at the beginning or end.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. margin
&lt;/h2&gt;

&lt;p&gt;This property will determine the distance between certain elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.your-class-name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-right&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;12px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="nt"&gt;shorthand&lt;/span&gt;
&lt;span class="nc"&gt;.your-class-name&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt; &lt;span class="m"&gt;12px&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 directly connect properties with sides by doing &lt;code&gt;margin-top&lt;/code&gt;, &lt;code&gt;margin-right&lt;/code&gt;, etc., or cover everything with a single &lt;code&gt;margin&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;margin&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;top&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;right&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;bottom&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;{&lt;/span&gt; &lt;span class="err"&gt;left&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you omit &lt;code&gt;bottom&lt;/code&gt;, it will inherit &lt;code&gt;top&lt;/code&gt; (check out our example)! If you omit &lt;code&gt;left&lt;/code&gt;, it will inherit &lt;code&gt;right&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. padding
&lt;/h2&gt;

&lt;p&gt;At the first glance, &lt;code&gt;padding&lt;/code&gt; looks similar to &lt;code&gt;margin&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;The syntax is identical as &lt;code&gt;margin&lt;/code&gt; too; shorthand as well.&lt;/p&gt;

&lt;p&gt;Why do we need it then?&lt;/p&gt;

&lt;p&gt;Imagine that you have a physical suitcase. You want to write something on the case.&lt;/p&gt;

&lt;p&gt;However, you don't want to start writing in the top-left corner. You want to indent your text a bit.&lt;/p&gt;

&lt;p&gt;For that, you will use &lt;code&gt;padding&lt;/code&gt;. Padding influences the inside of our element.&lt;/p&gt;

&lt;p&gt;However, if you have two suitcases next to each other and you want to make a distance between them, you'll use &lt;code&gt;margin&lt;/code&gt; for that. &lt;/p&gt;




&lt;h2&gt;
  
  
  4. background-color
&lt;/h2&gt;

&lt;p&gt;This one is pretty simple and an absolute necessity. You can apply this property to most of the HTML elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;blue&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;#232323&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;rgb&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;128&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;background-color&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;rgba&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;255&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;128&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;5&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Attributes can vary: from a simple color name, over its HEX value, to the RGB (even HSL).&lt;/p&gt;

&lt;p&gt;RGBA is interesting here because instead of just setting a color, you can also set the opacity. Seeing that 0.5? That means that transparency will be 50%.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. color
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;color&lt;/code&gt; is similar to &lt;code&gt;background-color&lt;/code&gt;; the only difference is that it influences the text's color. Everything else is the same, transparency included.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. opacity
&lt;/h2&gt;

&lt;p&gt;But we can make anything transparent!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;opacity&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;1&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="err"&gt;10&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nt"&gt;visibility&lt;/span&gt;
&lt;span class="nt"&gt;opacity&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="err"&gt;9&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="err"&gt;90&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nt"&gt;visibility&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is useful for disabled states or interesting effects.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. width
&lt;/h2&gt;

&lt;p&gt;This is a tricky one. Most of the time, you don't want to have fixed widths. Your design should be responsive and you can accomplish that with margins and paddings.&lt;/p&gt;

&lt;p&gt;However, sometimes you need to be fixed. Maybe you want to set your icon with to &lt;code&gt;24px&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;Or look at this article. Try to zoom out of the page. You'll see that it won't go from edge to edge.&lt;/p&gt;

&lt;p&gt;That's because the whole page has &lt;code&gt;max-width&lt;/code&gt; property. Useful to wrap your website with it.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. height 
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;height&lt;/code&gt; is much simpler than width due to the nature of our scroll direction.&lt;/p&gt;

&lt;p&gt;However, you'll still want to use as few fixed heights as possible. One example where you could is your header.&lt;/p&gt;

&lt;p&gt;All the other caveats like &lt;code&gt;min-height&lt;/code&gt; and &lt;code&gt;max-height&lt;/code&gt; exist here too.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. cursor: pointer;
&lt;/h2&gt;

&lt;p&gt;Hover over any button on this page. Can you see how the cursor changed into a little hand?&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cursor: pointer;&lt;/code&gt; is the reason for that. Whenever you can induce any actions (buttons, links, etc.) you need to use it.&lt;/p&gt;




&lt;h2&gt;
  
  
  10. font-size
&lt;/h2&gt;

&lt;p&gt;This one is pretty simple and controls the sizes of your font. If you're an absolute beginner, I recommend using only &lt;code&gt;px&lt;/code&gt; here.&lt;/p&gt;

&lt;p&gt;However, if you want to dig deeper, investigate &lt;code&gt;rem&lt;/code&gt;. Basically, you set your default font size in &lt;code&gt;px&lt;/code&gt;, and all the other fonts will be relative to that base value.&lt;/p&gt;

&lt;p&gt;For example, if your base value is &lt;code&gt;16px&lt;/code&gt;, &lt;code&gt;2rem&lt;/code&gt; will be &lt;code&gt;32px&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. font-family
&lt;/h2&gt;

&lt;p&gt;You want different fonts, right? Google Fonts are impressive and it's so easy to pick one of them, include them in your &lt;code&gt;index.html&lt;/code&gt;, and add its name to &lt;code&gt;font-family&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. :hover
&lt;/h2&gt;

&lt;p&gt;This will add any effects to a certain element on hover.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.your-class-name&lt;/span&gt;&lt;span class="nd"&gt;:hover&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&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;Our example will change the cursor to a pointer.&lt;/p&gt;




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

&lt;p&gt;What if I told you that you'll solve most of your CSS problems with these 12 properties?&lt;/p&gt;

&lt;p&gt;Sure, you'll maybe need a few more depending on your case, or you'll need to dig deeper into some of those.&lt;/p&gt;

&lt;p&gt;But this is enough to build a solid-looking website.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Check out the bottom of &lt;a href="https://link.medium.com/xYsyBfTwXib"&gt;the article originally published on Medium&lt;/a&gt; for the best CSS courses!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>html</category>
    </item>
    <item>
      <title>14 VS Code Shortcuts to Supercharge Your Productivity </title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Tue, 27 Jul 2021 15:28:48 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/14-vs-code-shortcuts-to-supercharge-your-productivity-4khn</link>
      <guid>https://dev.to/domagojvidovic/14-vs-code-shortcuts-to-supercharge-your-productivity-4khn</guid>
      <description>&lt;p&gt;We, software engineers, tend to be extremely efficient beings.&lt;/p&gt;

&lt;p&gt;Our goal is to optimize everything, not just the code.&lt;/p&gt;

&lt;p&gt;That's why we don't want to spend 10 seconds looking for something on the GUI. We don't want to spend even 2 seconds.&lt;/p&gt;

&lt;p&gt;Why would we, when we can do it in 0,1s by using the powerful keyboard shortcuts?&lt;/p&gt;

&lt;p&gt;If I repeatedly do the same actions, I always Google for its shortcut. Usually, I find it.&lt;/p&gt;

&lt;p&gt;Let me share with you the shortcuts I use every day. I bet you don't know many of them!&lt;/p&gt;




&lt;h3&gt;
  
  
  1. Search files by name
&lt;/h3&gt;

&lt;p&gt;Ok, we'll start by listing the most common and simples shortcuts.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cmd + P&lt;/code&gt; (Mac) / &lt;code&gt;crtl + P&lt;/code&gt; (Windows) will open a search field with an incredibly powerful fuzzy search. I probably use this 100+ times a day.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Search settings
&lt;/h3&gt;

&lt;p&gt;This one is similar; after clicking &lt;code&gt;cmd + P&lt;/code&gt; (Mac) / &lt;code&gt;crtl + P&lt;/code&gt; (Windows), just type &lt;code&gt;&amp;gt;&lt;/code&gt;. You can now type in any search term, and only settings will be affected.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Multiple cursors
&lt;/h3&gt;

&lt;p&gt;This feature is so cool, I wish I could use it everywhere else!&lt;/p&gt;

&lt;p&gt;Just press &lt;code&gt;alt&lt;/code&gt; and start clicking around the editor. Multiple cursors will appear!&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Multiple cursors v2
&lt;/h3&gt;

&lt;p&gt;You can do something similar without clicking around. &lt;code&gt;cmd option + arrow down&lt;/code&gt; (Mac) / &lt;code&gt;shift alt + arrow down&lt;/code&gt; (Windows) will insert an extra cursor below.&lt;/p&gt;

&lt;p&gt;Obviously, you can use &lt;code&gt;arrow up&lt;/code&gt; to insert a cursor above.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Select all occurrences
&lt;/h3&gt;

&lt;p&gt;This one is quite uncommon, but it's extremely powerful! First, you need to select some text.&lt;/p&gt;

&lt;p&gt;Then,&lt;code&gt;cmd shift + L&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + L&lt;/code&gt; (Windows) select all occurrences of that text. It's so useful for situations like renaming a variable across the file:&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%2Fuploads%2Farticles%2F1npwkhc4wih2nlfxzosb.gif" 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%2Fuploads%2Farticles%2F1npwkhc4wih2nlfxzosb.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Imagine manually renaming a variable repeated 30 times in the file. Nightmare.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Delete a line
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;cmd shift + K&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + K&lt;/code&gt; (Windows) does the trick here.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Duplicate a line
&lt;/h3&gt;

&lt;p&gt;Put your cursor in the line you want to duplicate.&lt;/p&gt;

&lt;p&gt;Press &lt;code&gt;cmd + C&lt;/code&gt;, then &lt;code&gt;cmd + V&lt;/code&gt; (Mac) / &lt;code&gt;crtl + C&lt;/code&gt;, then &lt;code&gt;crtl + V&lt;/code&gt; (Windows). Voila!&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Search in a file
&lt;/h3&gt;

&lt;p&gt;This one is quite familiar across all the common apps (like browsers): &lt;code&gt;cmd + F&lt;/code&gt; (Mac) / &lt;code&gt;crtl + F&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cmd + G&lt;/code&gt; (Mac) / &lt;code&gt;crtl + G&lt;/code&gt; (Windows) search for the next occurrence, while cmd &lt;code&gt;shift + G&lt;/code&gt; (Mac) / &lt;code&gt;crtl + shift + G&lt;/code&gt; (Windows) search for the previous one.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Replace in a file
&lt;/h3&gt;

&lt;p&gt;If you want to replace the term you searched for, fire &lt;code&gt;cmd option + G&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + G&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;p&gt;Then, click enter to replace the current occurrence.&lt;/p&gt;

&lt;p&gt;If you want to replace them all, click &lt;code&gt;cmd + enter&lt;/code&gt; (Mac) / &lt;code&gt;crtl + enter&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Search in all files
&lt;/h3&gt;

&lt;p&gt;Nothing can exist without a good old search in all files.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cmd shift + F&lt;/code&gt; (Mac) / &lt;code&gt;ctrl shift + F&lt;/code&gt; (Windows) does the trick.&lt;/p&gt;

&lt;p&gt;If you want to match text by case, press &lt;code&gt;cmd option + C&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + C&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;p&gt;You can also match the whole word by pressing &lt;code&gt;cmd option + W&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + W&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;h3&gt;
  
  
  11. Replace in all files
&lt;/h3&gt;

&lt;p&gt;Do you want to replace all occurrences in all files across the project, i.e. search/replace?&lt;/p&gt;

&lt;p&gt;Amazing, &lt;code&gt;cmd option + H&lt;/code&gt; (Mac) / &lt;code&gt;crtl shift + H&lt;/code&gt; (Windows) does the trick.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cmd option + enter&lt;/code&gt; (Mac) / &lt;code&gt;crtl alt + enter&lt;/code&gt; (Windows) triggers the replacement.&lt;/p&gt;

&lt;h3&gt;
  
  
  12. Split editor
&lt;/h3&gt;

&lt;p&gt;One tab is not enough, you need many of them! Great, just press &lt;code&gt;cmd + \&lt;/code&gt; (Mac) / &lt;code&gt;alt shift + 0&lt;/code&gt; (Windows). Repeat until you're satisfied.&lt;/p&gt;

&lt;h3&gt;
  
  
  13. Close tab
&lt;/h3&gt;

&lt;p&gt;This one is the same as in Chrome - &lt;code&gt;cmd + W&lt;/code&gt; (Mac) / &lt;code&gt;crtl + W&lt;/code&gt; (Windows).&lt;/p&gt;

&lt;h3&gt;
  
  
  14. Switching between opened tabs
&lt;/h3&gt;

&lt;p&gt;Do you want to open the previous tab? &lt;code&gt;crtl + tab&lt;/code&gt; does the trick.&lt;/p&gt;

&lt;p&gt;Do you want to go to a tab on a known position? &lt;code&gt;crtl + [index]&lt;/code&gt; does that.&lt;/p&gt;

&lt;p&gt;Finally, you can pick the tab on left/right by pressing &lt;code&gt;cmd option + arrow left/right&lt;/code&gt; (Mac) / &lt;code&gt;crtl page down/up&lt;/code&gt; (Windows).&lt;/p&gt;




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

&lt;p&gt;I wouldn't suggest learning all of them by heart immediately - try with one or two of them, and slowly adapt them to your work.&lt;/p&gt;

&lt;p&gt;Save this article in case you want to revisit it later.&lt;/p&gt;

&lt;p&gt;Using more keyboard shortcuts will increase your productivity.&lt;/p&gt;

&lt;p&gt;And oh, it does feel so good.&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>productivity</category>
      <category>javascript</category>
      <category>tooling</category>
    </item>
    <item>
      <title>11 Git Commands I Use Every Day</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Thu, 15 Jul 2021 15:48:36 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/11-git-commands-i-use-every-day-43eo</link>
      <guid>https://dev.to/domagojvidovic/11-git-commands-i-use-every-day-43eo</guid>
      <description>&lt;p&gt;When I started my career, I was always afraid of losing my code changes. Sometimes, I would copy the code to text files just to be sure that I won't miss something.&lt;/p&gt;

&lt;p&gt;That's not a great practice. If you know how to use git properly, you won't have these doubts.&lt;/p&gt;

&lt;p&gt;Git has everything you need to make you safe. And much more.&lt;/p&gt;

&lt;p&gt;Let's dive in.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Checking out a new branch
&lt;/h3&gt;

&lt;p&gt;Obviously, I must use a new branch for every task I start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout -b &amp;lt;new_branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command creates a new branch and automatically sets it as active.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Selecting files for commit
&lt;/h3&gt;

&lt;p&gt;This is one of the rare cases where I prefer GUI. In VS Code (or any other better IDE/text editor), you can easily see the updated files and select the ones you want to include in the commit.&lt;/p&gt;

&lt;p&gt;But in case you want to do it with the CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will stage all changed files.&lt;/p&gt;

&lt;p&gt;If you want to select a single file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;path/to/file&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Making a commit
&lt;/h3&gt;

&lt;p&gt;After you stage some files, you need to commit them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Some changes"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you have some pre-commit rules turned on which doesn't allow you to make a commit (like linting), you can override them by passing the --no-verify flag:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Some changes" --no-verify
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Revert all changes
&lt;/h3&gt;

&lt;p&gt;Sometimes, I experiment with the code. A bit later, I realize that it's not the right path and I need to undo all of my changes.&lt;/p&gt;

&lt;p&gt;One simple command for that is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --hard
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. See the latest commits
&lt;/h3&gt;

&lt;p&gt;I can easily see what's going on on my branch by typing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I can see the commit hashes, messages, authors, and dates.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Pulling the changes from the remote branch
&lt;/h3&gt;

&lt;p&gt;When I checkout an already existing branch (usually main or development), I need to fetch and merge the latest changes.&lt;/p&gt;

&lt;p&gt;There is a shorthand for that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes, if you're in one of your newly created branches, you'll also need to specify the origin branch:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull origin/&amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7. Undoing a local, unpushed commit
&lt;/h3&gt;

&lt;p&gt;I made a commit. Damn! Something's wrong here. I need to make one more change.&lt;/p&gt;

&lt;p&gt;No worries:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --soft HEAD~1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will revert your last commit and keep the changes you made.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;HEAD~1&lt;/code&gt; means that your head is pointing on one commit earlier than your current - exactly what you want.&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Undoing a pushed commit
&lt;/h3&gt;

&lt;p&gt;I made some changes and pushed them to remote. Then, I realized it's not what I want.&lt;/p&gt;

&lt;p&gt;For this, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git revert &amp;lt;commit_hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Be aware that this will be visible in your commit history.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Stashing my changes
&lt;/h3&gt;

&lt;p&gt;I'm in the middle of the feature, and my teammate pings me for an urgent code review.&lt;/p&gt;

&lt;p&gt;I obviously don't want to trash my changes, neither I want to commit them. I don't want to create a bunch of meaningless commits.&lt;/p&gt;

&lt;p&gt;I only want to check his branch and return to my work.&lt;/p&gt;

&lt;p&gt;To do so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// stash your changes
git stash
// check out and review your teammate's branch
git checkout &amp;lt;your_teammates_branch&amp;gt;
... code reviewing
// check out your branch in progress
git checkout &amp;lt;your_branch&amp;gt;
// return the stashed changes
git stash pop
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pop&lt;/code&gt; seems familiar here? Yep, this works like a stack.&lt;/p&gt;

&lt;p&gt;Meaning, if you do git stash twice in a row without git stash pop in between, they will stack onto each other.&lt;/p&gt;

&lt;h3&gt;
  
  
  10. Reseting your branch to remote version
&lt;/h3&gt;

&lt;p&gt;I messed something up. Some broken commits, some broken npm installs.&lt;/p&gt;

&lt;p&gt;Whatever I do, my branch is not working well anymore.&lt;/p&gt;

&lt;p&gt;The remote version is working fine. Let's make it the same!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git fetch origin
git reset --hard origin/&amp;lt;branch_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  11. Picking commits from other branches
&lt;/h3&gt;

&lt;p&gt;Sometimes, I want to apply the commits from the other branches. For this, I use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;commit_hash&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I want to pick a range:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git cherry-pick &amp;lt;oldest_commit_hash&amp;gt;^..&amp;lt;newest_commit_hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Let's be honest, I don't use all of these commands literally every day - but I use them really often.&lt;/p&gt;

&lt;p&gt;I prefer the CLI because we'll never be able to cover all the options with a GUI.&lt;/p&gt;

&lt;p&gt;Plus, you'll find most of the tutorials only using the CLI. If you're not familiar with it, you'll have a hard time understanding them.&lt;/p&gt;

&lt;p&gt;I covered the basics here, but whatever you need to do, just Google it.&lt;/p&gt;

&lt;p&gt;I'm certain that you'll find an answer easily.&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>programming</category>
      <category>codequality</category>
    </item>
    <item>
      <title>How To Structure a Massive Vuex Store for a Production App</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 12 Jul 2021 16:47:22 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/how-to-structure-a-massive-vuex-store-for-a-production-app-97a</link>
      <guid>https://dev.to/domagojvidovic/how-to-structure-a-massive-vuex-store-for-a-production-app-97a</guid>
      <description>&lt;p&gt;When looking at Vuex tutorials, you can see most of them are quite simple.&lt;/p&gt;

&lt;p&gt;The logic is explained well, but scalability suffers. How will this work in my production app?&lt;/p&gt;

&lt;p&gt;Here’s a simple store example from &lt;a href="https://vuex.vuejs.org/guide/#the-simplest-store" rel="noopener noreferrer"&gt;Vuex official docs&lt;/a&gt;:&lt;/p&gt;

&lt;div class="highlight js-code-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;Vue&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;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vuex&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&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;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;count&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="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;increment &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&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="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
A simple store



&lt;p&gt;There’s no need to explain this. I assume that you already have some Vue and Vuex knowledge prior to this article.&lt;/p&gt;

&lt;p&gt;My goal is not to explain what a store, state, or mutations are.&lt;/p&gt;

&lt;p&gt;Instead, I want to show you a massive store with 1,000+ state attributes, mutations, actions, and getters.&lt;/p&gt;

&lt;p&gt;I want to teach you how to structure the store for the best maintainability, readability, and reusability.&lt;/p&gt;

&lt;p&gt;It can have 100,000+ attributes. It would still be clear.&lt;/p&gt;

&lt;p&gt;Let’s dive in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meet Modules
&lt;/h2&gt;

&lt;p&gt;As we already said, keeping everything in one file will create a mess. You don’t want a 50,000+ LOC file. It’s the same as keeping your app in one component.&lt;/p&gt;

&lt;p&gt;Vuex helps us here by dividing the store into modules.&lt;/p&gt;

&lt;p&gt;For the purpose of this example, I will create a store with two modules. Note that the process is the same for 100+ modules, as well as 100+ actions, getters, and mutations within every module.&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;userModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;namespaced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="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="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;getters&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;organisationModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;namespaced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="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="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;actions&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;VueX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;modules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;userModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;organisation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;organisationModule&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;

&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="c1"&gt;// -&amp;gt; `userModule`'s state&lt;/span&gt;
&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;organisation&lt;/span&gt; &lt;span class="c1"&gt;// -&amp;gt; `organisationModule`'s state&lt;/span&gt;


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

&lt;/div&gt;
Updated store





&lt;p&gt;The &lt;code&gt;namespaced&lt;/code&gt; attribute is incredibly important here. Without it, actions, mutations, and getters would still be registered at the global namespace.&lt;/p&gt;

&lt;p&gt;With the &lt;code&gt;namespaced&lt;/code&gt; attribute set to true, we divide actions, mutations, and getters into the modules as well.&lt;/p&gt;

&lt;p&gt;This is really helpful if you have two actions with the same name. Having them in a global namespace would create clashes.&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;userModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;namespaced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="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="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER_LOCATION&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="na"&gt;getters&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;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt; &lt;span class="c1"&gt;// correct ✅&lt;/span&gt;

&lt;span class="nx"&gt;stote&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;SET_USER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]()&lt;/span&gt; &lt;span class="c1"&gt;// wrong ❌&lt;/span&gt;


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

&lt;/div&gt;
Namespaced module





&lt;p&gt;As you can see, the module is completely “local” right now. We can access it only through the user object on the state.&lt;/p&gt;

&lt;p&gt;Exactly what we want for our massive application.&lt;/p&gt;




&lt;p&gt;Cool, now we have a store divided into modules!&lt;/p&gt;

&lt;p&gt;However, I don’t like the hardcoded strings for actions. It’s definitely not maintainable. Let’s address this issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Types To Save You From Headaches
&lt;/h2&gt;

&lt;p&gt;We don’t just want to access every property from every module in every file. That sentence sounds like hell.&lt;/p&gt;

&lt;p&gt;We want to import them first. Then use &lt;code&gt;mapGetters&lt;/code&gt;, &lt;code&gt;mapActions&lt;/code&gt;, or &lt;code&gt;mapMutations&lt;/code&gt; to achieve that.&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;// userModule.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SET_USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SET_USER_LOCATION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER_LOCATION&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;userModule&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;namespaced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&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="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="na"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt;
  &lt;span class="na"&gt;actions&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;SET_USER&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;SET_USER_LOCATION&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="na"&gt;getters&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;// vue file&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;mapActions&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&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;SET_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SET_USER_LOCATION&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;./userModule.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nf"&gt;mapActions&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;setUser&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SET_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;setUserLocation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;SET_USER_LOCATION&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
Access actions with mapActions





&lt;p&gt;This gives you a clear view of store attributes used by your Vue file.&lt;/p&gt;

&lt;p&gt;But that’s not enough. Everything is still in one file. Let’s see what we can do to scale it properly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Folder Structure
&lt;/h2&gt;

&lt;p&gt;Ideally, we want to split modules into different folders. Within those modules, we want to split their mutations, actions, getters, state attributes, and types across different files.&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%2Fuploads%2Farticles%2Fjumfdh6gb3wedgtg8rrk.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%2Fuploads%2Farticles%2Fjumfdh6gb3wedgtg8rrk.png" alt="The desired folder structure"&gt;&lt;/a&gt;&lt;/p&gt;
The desired folder structure





&lt;p&gt;Folder &lt;code&gt;store&lt;/code&gt; will be created in the root folder of our project.&lt;/p&gt;

&lt;p&gt;It will contain two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;index.js&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;modules&lt;/code&gt; folder&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before explaining the &lt;code&gt;index.js&lt;/code&gt; file, let’s see how we divide a single module. Let’s check the &lt;code&gt;user&lt;/code&gt; module.&lt;/p&gt;

&lt;p&gt;All of its actions, mutations, and getters should be listed in the &lt;code&gt;types.js&lt;/code&gt; file. So, something like:&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;// actions&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SET_USER&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SET_USER_LOCATION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SET_USER_LOCATION&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// mutations&lt;/span&gt;

&lt;span class="c1"&gt;// getters&lt;/span&gt;


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

&lt;/div&gt;
store/modules/user/types.js





&lt;p&gt;We’ll have a clear view by importing those consts every time we want to use them.&lt;/p&gt;

&lt;p&gt;Let’s look at the actions now. We want to move them to the &lt;code&gt;actions.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;To do so, we only need to copy the &lt;code&gt;actions&lt;/code&gt; object within the module and &lt;code&gt;export default&lt;/code&gt; it, while importing the types:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;SET_USER&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;SET_USER_LOCATION&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;./types.js&lt;/span&gt;&lt;span class="dl"&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="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;SET_USER&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;SET_USER_LOCATION&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;
store/modules/user/actions.js





&lt;p&gt;We will do the same thing for mutations and getters. The state attributes will remain in &lt;code&gt;index.js&lt;/code&gt; (within the user module folder):&lt;/p&gt;

&lt;div class="highlight js-code-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;actions&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;./actions.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;mutations&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;./mutations.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;getters&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;./getters.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;state&lt;/span&gt; &lt;span class="o"&gt;=&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="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;namespaced&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getters&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;
store/modules/user/index.js





&lt;p&gt;Now we have all of our modules divided into multiple files.&lt;/p&gt;

&lt;p&gt;The one thing remaining is to link all those modules in the &lt;code&gt;index.js&lt;/code&gt; file within the &lt;code&gt;store&lt;/code&gt; folder:&lt;/p&gt;

&lt;div class="highlight js-code-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;Vue&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;vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vuex&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;vuex&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="c1"&gt;// Modules import&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;UserModule&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;modules/user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;OrganisationModule&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;modules/organisation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Vuex&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;state&lt;/span&gt; &lt;span class="o"&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;actions&lt;/span&gt; &lt;span class="o"&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;mutations&lt;/span&gt; &lt;span class="o"&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;getters&lt;/span&gt; &lt;span class="o"&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;modules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;user&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;userModule&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;organisation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;organisationModule&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="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;actions&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;mutations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;getters&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;modules&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;


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

&lt;/div&gt;
store/index.js





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

&lt;p&gt;By using this architecture, we had zero problems with scalability in our massive production app.&lt;/p&gt;

&lt;p&gt;Everything is so easy to find.&lt;/p&gt;

&lt;p&gt;We know exactly where all the actions are triggered.&lt;/p&gt;

&lt;p&gt;The system is highly maintainable.&lt;/p&gt;

&lt;p&gt;If you have any recommendations for the improvements, please let me know. I would love to hear your opinion.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why is the Virtual DOM So Fast?</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Wed, 07 Jul 2021 14:04:09 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/why-is-the-virtual-dom-so-fast-o6e</link>
      <guid>https://dev.to/domagojvidovic/why-is-the-virtual-dom-so-fast-o6e</guid>
      <description>&lt;p&gt;When you start learning about the frontend world, you’ll almost immediately stumble across the term “Virtual DOM”.&lt;/p&gt;

&lt;p&gt;Most of the popular frontend frameworks use it and want to prove their speed with it.&lt;/p&gt;

&lt;p&gt;But what makes it so fast?&lt;/p&gt;

&lt;p&gt;And what makes the real DOM so slow and inefficient?&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Browser Rendering
&lt;/h2&gt;

&lt;p&gt;This topic is quite complicated, but you need to know the basics to understand the DOM.&lt;/p&gt;

&lt;p&gt;Let’s assume that we request a simple HTML/CSS page from the server; we won’t need JS here.&lt;/p&gt;

&lt;p&gt;After we receive a response in the form of HTML/CSS, this happens:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Parsing the HTML
&lt;/h3&gt;

&lt;p&gt;The browser parses the HTML file and stores it in memory as an efficient tree structure.&lt;/p&gt;

&lt;p&gt;That representation is called DOM — Document Object Model. You can see it by opening the DevTools, and selecting the “Elements” tab.&lt;/p&gt;

&lt;p&gt;Just to be clear, DOM is not HTML! It’s just an interface for HTML and XML files.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Parsing the CSS
&lt;/h3&gt;

&lt;p&gt;This step includes parsing the CSS — and storing it as a tree structure. It’s referred to as CSSOM.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Creating the Render Tree
&lt;/h3&gt;

&lt;p&gt;When you combine DOM and CSSOM, you get a render tree. It’s made out of HTML nodes and their styles, and it represents what is rendered in the browser.&lt;/p&gt;

&lt;p&gt;This won’t include every HTML node — e.g.&lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;, but also elements with &lt;code&gt;display: none;&lt;/code&gt;. Just the ones that are actually visible on the screen.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Layout Stage
&lt;/h3&gt;

&lt;p&gt;The purpose of this stage is to calculate the positions of every node in the render tree. The browser will begin at the root and traverse the tree.&lt;/p&gt;

&lt;p&gt;As you can imagine, this process can be expensive because it has to do loads of calculations for every node in the tree.&lt;br&gt;
At the end of this stage, the browser knows each element’s exact position and size.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Paint Stage
&lt;/h3&gt;

&lt;p&gt;Finally, we can fill the empty skeleton we’ve got after the Layout Stage.&lt;/p&gt;

&lt;p&gt;The browser literally has to go through every pixel in the viewport which has to be filled. Sounds expensive, right?&lt;/p&gt;

&lt;p&gt;Well, it is. This is definitely the most computational heavy step.&lt;/p&gt;

&lt;p&gt;You can inspect the Layout and Paint Stages in DevTools under the “Performance” tab.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s Do the Math
&lt;/h2&gt;

&lt;p&gt;As you probably already know, tree structures are incredibly efficient. The algorithms we have can traverse the enormous trees without too much effort.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It’s really cheap to do it.&lt;/strong&gt; And that’s what steps 1–3 are all about.&lt;/p&gt;

&lt;p&gt;On the other side, steps 4 and 5 can be incredibly expensive because we have additional steps of manipulating every pixel on the screen. Those algorithms are efficient, but still so slow compared to a tree structure.&lt;/p&gt;

&lt;p&gt;Obviously, our initial page render will take a bit longer and Virtual DOM won’t help us much. We don’t have anything on the screen yet, right?&lt;/p&gt;

&lt;p&gt;But later, when we make updates, Virtual DOM will go through steps 1–3. It will compare the new render tree with the previous one, and do steps 4–5 only for the modified nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That’s what makes it so fast!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It doesn’t need to do a whole process from the scratch. It will re-render (steps 4 and 5) only the modified nodes!&lt;/p&gt;

&lt;p&gt;The best thing is — you don’t need to take care of it. Your magical FE tool does that for you.&lt;/p&gt;

&lt;p&gt;If you read about &lt;a href="https://reactjs.org/docs/optimizing-performance.html"&gt;Optimizing Performance in React’s official docs&lt;/a&gt;, you can see:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Internally, React uses several clever techniques to minimize the number of costly DOM operations required to update the UI. For many applications, using React will lead to a fast user interface without doing much work to specifically optimize for performance.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So don’t make unnecessary optimizations. Most of the time, the complexity behind those optimizations will result in a slower code.&lt;/p&gt;

&lt;p&gt;Love and praise the VDOM.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How I Prioritize My Work as a Software Engineer</title>
      <dc:creator>Domagoj Vidovic</dc:creator>
      <pubDate>Mon, 14 Jun 2021 14:15:41 +0000</pubDate>
      <link>https://dev.to/domagojvidovic/how-i-prioritize-my-work-as-a-software-engineer-36h4</link>
      <guid>https://dev.to/domagojvidovic/how-i-prioritize-my-work-as-a-software-engineer-36h4</guid>
      <description>&lt;p&gt;Somewhere in the middle of my career, my coding skills started to grow rapidly.&lt;/p&gt;

&lt;p&gt;I surrounded myself with the best engineers. I got the best mentorship.&lt;/p&gt;

&lt;p&gt;Every pull request was an invaluable lesson.&lt;/p&gt;

&lt;p&gt;However, being a great developer is much more than writing amazing code. We are team players, and we must act like it.&lt;/p&gt;

&lt;p&gt;Soft skills, if you focus on them, can improve your career more than your technical skills.&lt;/p&gt;

&lt;p&gt;Just a few engineers who work closely with you will be aware of your code quality. However, if you’re a great team player, everyone will know it.&lt;/p&gt;

&lt;p&gt;Let me share a few things I changed at my work that completely transformed my career.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Was Doing Wrong
&lt;/h2&gt;

&lt;p&gt;At the time, I was obsessed with deep work and the flow state. I put my noise-canceling headphones on, started coding, avoided all distractions, and let the code fill my mind.&lt;/p&gt;

&lt;p&gt;Sometimes, I succeeded in retaining that state for hours. It was amazing. I was learning so much and it felt so good.&lt;/p&gt;

&lt;p&gt;Today, I have nothing against the flow state. Hey, I’m currently in it while writing this article. I have no distractions. My phone is on silent mode and I know I won't speak to anyone before I finish.&lt;/p&gt;

&lt;p&gt;But there’s a huge difference. When writing, I’m all alone.&lt;/p&gt;

&lt;p&gt;When coding for a company, I’m a team player.&lt;/p&gt;

&lt;p&gt;I can’t snooze all my notifications. I can’t be unresponsive. My team needs me in the same way I need them.&lt;/p&gt;

&lt;p&gt;And that’s exactly what I was doing. Sometimes, it took me an hour or even longer to respond to a simple Slack message.&lt;/p&gt;

&lt;p&gt;When people asked me to do something that would take five minutes, I ignored that task for days.&lt;/p&gt;

&lt;p&gt;I was constantly pursuing that magical flow state. I didn’t want to let any distractions come to my mind.&lt;/p&gt;

&lt;p&gt;In my head, I had a right to do that. I was writing the best code possible and focusing just on that. What’s the problem?&lt;/p&gt;

&lt;h2&gt;
  
  
  What My Colleagues Thought About Me
&lt;/h2&gt;

&lt;p&gt;If we take a different perspective and look at it from the eyes of my colleagues, we will see that my behavior wasn’t justified.&lt;/p&gt;

&lt;p&gt;They needed to do something for work, so they asked me for help. However, those requests always landed at the bottom of my priority list.&lt;/p&gt;

&lt;p&gt;I gave them solutions hours or even days later.&lt;/p&gt;

&lt;p&gt;Sometimes, the solution wasn’t so great. I didn’t want to spend too much time on those small tasks.&lt;/p&gt;

&lt;p&gt;“Let me keep my flow state!”&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Changed
&lt;/h2&gt;

&lt;p&gt;Every once in a while, we have anonymous team reviews. Basically, you write about the people you work with. After the sessions, the team leaders tell you what others are saying about you.&lt;/p&gt;

&lt;p&gt;I received many positive comments about my engineering skills.&lt;/p&gt;

&lt;p&gt;However, some comments were quite negative, and they were all connected to my prioritization and communication techniques.&lt;/p&gt;

&lt;p&gt;People were saying that I was unresponsive or gave them solutions that hadn’t been fully tested.&lt;/p&gt;

&lt;p&gt;How could I test them properly when I had to return to the flow state as soon as possible?&lt;/p&gt;

&lt;p&gt;I took that opportunity to self-reflect and change.&lt;/p&gt;

&lt;p&gt;What I did was incredibly simple. However, it completely transformed my career.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Simple Changes
&lt;/h2&gt;

&lt;p&gt;When somebody asked me for help, I immediately responded. Their request was now my top priority.&lt;/p&gt;

&lt;p&gt;Most of the time, it’s not a time-consuming task. It’s a question about where something is located in the app, what the expected behavior is, what that code means, etc.&lt;/p&gt;

&lt;p&gt;I can handle those tasks in 1-2 minutes. Occasionally, it takes me 5-10 minutes if they are a bit more complex.&lt;/p&gt;

&lt;p&gt;Besides just responding to my direct messages, I also became an instant responder in our groups. Suddenly, I became a person others rely on when they need quick information or changes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Astonishing Effects
&lt;/h2&gt;

&lt;p&gt;From being an unresponsive person who coded in the corner with his noise-canceling headphones, I became one of the most valuable people in the company.&lt;/p&gt;

&lt;p&gt;Everyone has that feeling of trust: When they ask me something, they know the solution will be there in the shortest time possible.&lt;/p&gt;

&lt;p&gt;People don’t expect that, so they love it even more! I often receive compliments about how great my work is and how fast I deliver it.&lt;/p&gt;

&lt;p&gt;My colleagues have problems they need to solve. If I help them in two minutes, they will be amazed.&lt;/p&gt;

&lt;p&gt;However, if I help them in three-plus hours, they won’t be impressed. They may even be annoyed if it’s something really simple.&lt;/p&gt;

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

&lt;p&gt;For the sake of simplicity, imagine that I’m working on a task that needs six hours to be finished. I started my work at 9 a.m. If I do nothing but code, I will finish it at 3 p.m.&lt;/p&gt;

&lt;p&gt;However, I’m not the only one who’s working. Everybody else is, and they need my help. In the period from 9 to 11 a.m., three people ask for my help.&lt;/p&gt;

&lt;p&gt;The tasks are pretty simple. Each one will take around five minutes to complete.&lt;/p&gt;

&lt;p&gt;We have two possible scenarios about handling this work:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the first one, I’m the old, unresponsive team member. It takes me about one hour to respond to somebody’s message, and it goes at the bottom of my priorities list. I will do it after I finish my task. That means that I’m done with my feature at 3 p.m. However, that also means those three people waited 4-6 hours for my solutions. They are grumpy because they wanted to do something by noon. However, they were blocked by me.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In the second scenario, I respond and do the job immediately. I receive comments like “Amazing, that was so fast 🚀” or “Wow, I can do this before lunch now, thanks Dom 🏎.” Besides all that, I finish my feature at 3:15 p.m.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Can you see the difference?&lt;/p&gt;

&lt;p&gt;Nobody cares about me finishing the feature 15 minutes later because they didn’t know when I was expected to finish it anyway.&lt;/p&gt;

&lt;p&gt;However, they certainly care about me providing them with a solution in five minutes rather than five hours.&lt;/p&gt;

&lt;p&gt;Again, just a few people can see your code skills. However, most of them will see your communication skills.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Did This Influence My Coding Skills?
&lt;/h2&gt;

&lt;p&gt;We, as engineers, need to solve extremely complex problems that require a lot of focus. Sometimes, context switching can destroy those solutions in our minds.&lt;/p&gt;

&lt;p&gt;However, a context switch can also be the break you need. When you return, you’ll be able to take a step back and look at the problem from a different perspective.&lt;/p&gt;

&lt;p&gt;If you had stayed there for a few more hours, you would have just drilled in the wrong direction.&lt;/p&gt;

&lt;p&gt;Suddenly, you return after a break and fix the issue in a few minutes.&lt;/p&gt;

&lt;p&gt;So those breaks actually improve my coding skills. I ship the code even faster now.&lt;/p&gt;

&lt;p&gt;Sometimes, the best solution is to let go. A fix will quickly come after we stop being obsessed with it.&lt;/p&gt;

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

&lt;p&gt;This is not just for your benefit — everybody’s included.&lt;/p&gt;

&lt;p&gt;These skills will make you a great team player. A person others can rely on. You will radiate confidence and solve people’s problems in no time.&lt;/p&gt;

&lt;p&gt;Nobody’s pipeline will be blocked because of you. Everything just flows. You make others feel happy and inspired.&lt;br&gt;
You’re not alone, so stop acting like that.&lt;/p&gt;

&lt;p&gt;You can be an incredible engineer, but if you manage to be an incredible team player as well, you’ll easily become part of the top 1%.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>career</category>
    </item>
  </channel>
</rss>
