<?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: Vijay Joshi</title>
    <description>The latest articles on DEV Community by Vijay Joshi (@vijayjoshi).</description>
    <link>https://dev.to/vijayjoshi</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%2F454107%2Fb5e2ceae-821f-44cf-961b-03a51a38067c.jpeg</url>
      <title>DEV Community: Vijay Joshi</title>
      <link>https://dev.to/vijayjoshi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vijayjoshi"/>
    <language>en</language>
    <item>
      <title>9 simple steps to optimize your web application performance</title>
      <dc:creator>Vijay Joshi</dc:creator>
      <pubDate>Wed, 02 Sep 2020 13:09:04 +0000</pubDate>
      <link>https://dev.to/vijayjoshi/optimizing-single-page-and-web-applications-performance-4cnn</link>
      <guid>https://dev.to/vijayjoshi/optimizing-single-page-and-web-applications-performance-4cnn</guid>
      <description>&lt;p&gt;&lt;em&gt;This post was originally published on my company website: &lt;a href="https://www.corevaluetech.com/blog/optimizing-single-page-and-web-applications-performance"&gt;link&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;With the browsers becoming more and more advanced and supporting multiple new technologies now and web apps supporting rich content, it has become more important to focus on performance of web applications. These include both Single Page Applications(aka SPAs) and traditional server side rendered web applications.&lt;/p&gt;

&lt;p&gt;In this article we will look at some steps that can be taken to improve the performance of web applications.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove duplicate JavaScript and CSS
&lt;/h3&gt;

&lt;p&gt;Loading duplicate JS and CSS files has multiple drawbacks. For one the increased number of network requests which will make your site slower. Secondly, in case of some scripts, these scripts can collide and cause unexpected behavior. And finally Google can punish the website in search results.&lt;/p&gt;

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

&lt;p&gt;Hence always ensure that all the JS and CSS files that you are loading are not duplicated.&lt;/p&gt;

&lt;h3&gt;
  
  
  Minify JavaScript and CSS
&lt;/h3&gt;

&lt;p&gt;Rather than serving your JavaScript and CSS files in as is condition, you can use an automated tool to minify them. It will remove all unnecessary comments, white spaces and will make your file sizes smaller. This means less data is transferred and reduced bandwidth usage.&lt;/p&gt;

&lt;p&gt;There are multiple tools like minifyjs, js compress etc available. Bundlers like webpack are configured by default to minify the files while building for production.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compress components with gzip
&lt;/h3&gt;

&lt;p&gt;We can make further improvements to the point mentioned above. Enter &lt;a href="https://varvy.com/pagespeed/enable-compression.html"&gt;gzip&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;gzip is a technique of compressing and decompressing data very fast. Server could send the data gzipped over the network and browser will decompress it once received. &lt;/p&gt;

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

&lt;p&gt;It can result in a reduced size of up to 60%. So if you are loading a JS file of 500KB normally. with gzip the network transfer will be of only 300KB. This could result in a large number based on how many scripts, css you serve. Significant performance improvement will be visible if you load a large number of JS and CSS files. e.g. w WordPress site multiple plugins being used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Place scripts at bottom
&lt;/h3&gt;

&lt;p&gt;If you place you scripts on the top, in head section of the document, document underneath will not load because browsers will wait for all the scripts to load first. This will result in an empty looking page on your website. However, if you keep them at the bottom, the html doc will load first and your users will not be staring at a blank screen and will have something to look at on your website.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lighthouse
&lt;/h3&gt;

&lt;p&gt;Use a tool like &lt;a href="https://developers.google.com/web/tools/lighthouse"&gt;lighthouse&lt;/a&gt; from Google to identify the bottlenecks and areas of improvement in your web application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5rXoVDCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4d11w4vk2v17yym4eyrk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5rXoVDCS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/4d11w4vk2v17yym4eyrk.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lighthouse measures your website on multiple parameters and generates a score for each one of them. It also provides suggestions on how the scores can be improved. Best practices are also mentioned in the results.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use a bundle analyzer
&lt;/h3&gt;

&lt;p&gt;This point relates to SPAs specifically. Since there is a npm package for almost everything today, developers end up using a lot of them. Some of those might contain poorly written code and have large bundle sizes. These can end up being a performance bottleneck for your application. For example, you can be using an external library for date formatting or string utilities which can have large sizes. &lt;/p&gt;

&lt;p&gt;A &lt;a href="https://www.npmjs.com/package/webpack-bundle-analyzer"&gt;bundle analyzer&lt;/a&gt; can visually show you the different bundles/packages being used in your application along with their sizes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7Ev0Mbhi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pihjw8c2eeta5gmf9yuy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7Ev0Mbhi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/pihjw8c2eeta5gmf9yuy.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This can potentially help in identifying which bundles are large and need to be further broken down or need to have an alternative for them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tree Shaking
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking"&gt;Tree shaking&lt;/a&gt; is a pattern used for dead code elimination(aka DCE). Let's take a common example. You are using the lodash library in your project. It provides multiple methods for different tasks. But in your project you are only using a handful of them, say 10 out of 50. In this case when you build your project, the entire lodash library is included. Which means the remaining 40 methods are not being used but are still in the bundle. It is certainly unnecessary and causing bundle size to increase which will directly affect the loading time of your app. &lt;/p&gt;

&lt;p&gt;Now to avoid this, you should export only the methods you have used in your code. Bundlers like webpack already support this. On your end instead of importing the whole lodash library, you should only import the method that you want to use. This will ensure that webpack only includes the necessary methods in the build and leaves the rest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Code splitting
&lt;/h3&gt;

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

&lt;p&gt;Bundlers like webpack provide a very powerful feature which if used can make your web app significantly faster. As the name suggests, &lt;a href="https://webpack.js.org/guides/code-splitting/"&gt;code splitting&lt;/a&gt; is a method where code can be split in various small chunks instead of having a single bundle with all the code. These chunks get loaded dynamically based on the page user is visiting.&lt;/p&gt;

&lt;p&gt;Above image is from a real project where you can see all the different chunks. Only chunks specific to a page are loaded making the page faster to load.&lt;/p&gt;

&lt;h3&gt;
  
  
  Optimize the images
&lt;/h3&gt;

&lt;p&gt;Based on use case, large image size can adversely affect the performance of you website. Take the example of an e-commerce site where products are displayed in a grid. Each product has an image and a description and clicking on a product takes the user to product details page where full size image of product is displayed. If the product images are of large size, the grid page can take a significant time to load resulting in a bad user experience.&lt;/p&gt;

&lt;p&gt;This problem is easy to solve. What you need to do is to create, compress and store multiple sizes of an image when it is uploaded. Example sizes can be: thumbnail, small, medium, large and original. Based on context and page appropriate image can be used.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you for reading!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>webpack</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Git: Reset to an older git commit</title>
      <dc:creator>Vijay Joshi</dc:creator>
      <pubDate>Wed, 02 Sep 2020 11:34:30 +0000</pubDate>
      <link>https://dev.to/vijayjoshi/git-reset-to-an-older-git-commit-5dcf</link>
      <guid>https://dev.to/vijayjoshi/git-reset-to-an-older-git-commit-5dcf</guid>
      <description>&lt;p&gt;This is more of a note to self on how to permanently delete commits from git.&lt;/p&gt;

&lt;p&gt;I forgot to add a config file to .gitignore while working on a public project and it ended up on github when I pushed it. I did add it to .gitignore later but it was there for anyone if they checked my previous commit.&lt;/p&gt;

&lt;p&gt;Anyway, here are some quick commands if you want to reset your git branch. Normally rebase is the way to do it but my repo had just a handful of commits and has not any precious data, so I did it the quick and dirty way.&lt;/p&gt;

&lt;p&gt;Type the following to see you git commits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;git log
This will list a &lt;span class="nb"&gt;history &lt;/span&gt;of your commits with respective commit ids:
commit 15e227a3a0a201295296302b391a28ef &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; master, origin/master&lt;span class="o"&gt;)&lt;/span&gt;
Author: Vijay Joshi 
Date:   Tue Aug 18 20:36:09 2020 +0530
removed .firebaserc
commit d3e0f41f84ed41a432750070fac1b6e
Author: Vijay Joshi 
Date:   Tue Aug 18 20:34:46 2020 +0530
&lt;span class="nb"&gt;test &lt;/span&gt;commit
commit 4a73669e5fb47b0b9d488b1865b7e
Author: Vijay Joshi 
Date:   Tue Aug 18 20:34:07 2020 +0530
added .firebaserc sample
commit 279955296678df915eb8b094b76be
Author: Vijay Joshi 
Date:   Tue Aug 18 20:26:49 2020 +0530
Updated readme
commit 08794a0476f2616c2090146a05f7
Author: Vijay Joshi 
Date:   Tue Aug 18 20:24:46 2020 +0530
...skipping...
commit 27ad40be15e227a3a0a201295296302b391a28ef &lt;span class="o"&gt;(&lt;/span&gt;HEAD -&amp;gt; master, origin/master&lt;span class="o"&gt;)&lt;/span&gt;
Author: Vijay Joshi
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I made the mistake in third commit from the top, so I wanted to reset my repo to fourth commit from top. Here are the commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git reset --hard commit_id
git push origin HEAD --force
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;WARNING:&lt;/strong&gt; Doing this will remove all commits newer than the commit id provided above and you will lose all your changes before this commit. So, make sure you have taken backup of your repo beforehand.&lt;/p&gt;

&lt;p&gt;All I want to say in the end is, make sure you are attentive earlier, it is a dirty way to cleanup and is somewhat I would advise using as a last resort.&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
