<?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: Rajat Jain</title>
    <description>The latest articles on DEV Community by Rajat Jain (@rajat315315).</description>
    <link>https://dev.to/rajat315315</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%2F449325%2F701cf4e4-f2fd-4db3-94c1-c6500404d94f.jpeg</url>
      <title>DEV Community: Rajat Jain</title>
      <link>https://dev.to/rajat315315</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajat315315"/>
    <language>en</language>
    <item>
      <title>Improving Google PageSpeed Score</title>
      <dc:creator>Rajat Jain</dc:creator>
      <pubDate>Fri, 21 Aug 2020 10:30:45 +0000</pubDate>
      <link>https://dev.to/rajat315315/improving-google-pagespeed-score-1gaa</link>
      <guid>https://dev.to/rajat315315/improving-google-pagespeed-score-1gaa</guid>
      <description>&lt;h2&gt;
  
  
  Wakefit Engineering
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;How we improved our PageSpeed score from 46 to 82 on wakefit.co?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flxl9kx2takv9zkw26so3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flxl9kx2takv9zkw26so3.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk0z5zoxjjf4sjk8pfgnz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk0z5zoxjjf4sjk8pfgnz.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wakefit serves around one million visitors every month. It has all sorts of furniture categories consisting around 50 Product pages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For HomePage,&lt;br&gt;
Earlier, we used to make around &lt;strong&gt;190 requests&lt;/strong&gt; and Page size was &lt;strong&gt;5 Mb.&lt;/strong&gt;&lt;br&gt;
Now, we make only &lt;strong&gt;56 requests&lt;/strong&gt; with Page size reduced to half &lt;strong&gt;3 Mb.&lt;/strong&gt;&lt;br&gt;
One can also see that load time has also increased by 4X (from 12s to 3s.)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Below are the steps we followed to make this change..&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Using webP format for all Images instead of JPEG. (saved 2 Mb)&lt;/li&gt;
&lt;li&gt;Combining all &lt;em&gt;CSS&lt;/em&gt; into a single CSS file. (saved 10 trips)&lt;/li&gt;
&lt;li&gt;Combining all &lt;em&gt;JS&lt;/em&gt; into one JS file. (saved 15 trips)&lt;/li&gt;
&lt;li&gt;Introduced &lt;strong&gt;Cache-Control Headers&lt;/strong&gt; for static assets like Images, JS, CSS.&lt;/li&gt;
&lt;li&gt;Small SVG (1–5kB) files are &lt;em&gt;embedded&lt;/em&gt; into html. saved 25 trips)&lt;/li&gt;
&lt;li&gt;Using &lt;strong&gt;Native Image Lazy-Loading&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Pre-Loading essential assets like critical images, fonts &amp;amp; 8. Pre-connecting to important third-party servers in-advance.&lt;/li&gt;
&lt;li&gt;Converting fonts to &lt;strong&gt;modern woff2 format&lt;/strong&gt; having in-built compression) instead of regular ttf.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  --------
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Let's get in detail:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Since our website was Image heavy, we switched to a more optimal Image format i.e. &lt;strong&gt;webP&lt;/strong&gt;.&lt;br&gt;
Our homepage itself loads more than 40 images constituting more than 2 Mb of data, when converted to webP saved half of the space ~1Mb.&lt;br&gt;
For the fact, our whole AWS S3 bucket used to consist of more than 200 MB of JPEG images which when converted to webP costed only ~100MB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We used to serve around 14 CSS files for every new user which was a lot.&lt;br&gt;
We combined them into a single CSS file, minified it, &amp;amp; served it with &lt;strong&gt;gzip/brotli&lt;/strong&gt; compression.&lt;br&gt;
Thus, saving all those 14 HTTP requests. Earlier our CSS files for HomePage costed us ~500KB which now rests at ~40KB. &lt;strong&gt;(Huge 10X Savings!!!)&lt;/strong&gt;&lt;br&gt;
Earlier, we use to load 14 CSS files for each visit.Now, compresed into single CSS file &amp;amp; use gZip compression.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd87lek8sekf8gflcosb1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fd87lek8sekf8gflcosb1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We used to make 44 calls to download different Javascript files. These included third-party scripts such as bootstrap, owl-carousel, jQuery, several analytics plugins &amp;amp; custom javascripts. Huge, right???
In our investigation journey, we found that some of them could luckily be removed &amp;amp; rest can be combined into 2 bundles. One critical file, which is needed right at the start. Another file/bundle is less critical involving Analytics plugins &amp;amp; carousels.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fptvez77aeq735bordzw5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fptvez77aeq735bordzw5.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Now, since we served all the Images from our Amazon S3 bucket, it must be under huge load as every visit requires fetching of Images from the server.&lt;br&gt;
To resolve this, we added the Cache-Control header to each Image resource and set it to expire 1 month from now.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Results: Our server load reduced by HALF!!!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We noticed ~20 calls were made to retrieve small SVG images on homepage which includes small icons of social media, user, etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We had two options:&lt;br&gt;
Either we put Cache-Control header so that every repeating visitor is saved from downloading it again. But in this case, every user anyhow has to make all ~20 calls to download all of them at first place.&lt;br&gt;
Secondly, we can embed all of them in the HTML document in base64 encoding. This method would indeed save us from all those ~20 HTTP download calls. But the downside would be that now we can't use Caching.&lt;br&gt;
After careful consideration, we chose option 2) to enhance first-time users experience.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lazy Loading is a great technique to save a lot of bandwidth. It can be applied in various ways using external javascript, writing our own scripts or using&lt;br&gt;
&lt;br&gt;
&lt;code&gt;&amp;lt;img loading=`lazy` src=``&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
attribute.&lt;br&gt;
We used the native lazy-loading which saved us around 40% of bandwidth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next came the turn of Analytic plugins. As every e-commerce is loaded with tons of plugins to deeply analyze its customers, we were also not behind, running around 5–10 different plugins.&lt;br&gt;
After taking a collaborative decision, we removed some plugins saving us a few more network calls.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Analysis across Competitors
&lt;/h4&gt;

&lt;p&gt;Wakefit lies in the e-commerce bucket in India and has many competitors like&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Amazon.in&lt;/li&gt;
&lt;li&gt;Flipkart.com&lt;/li&gt;
&lt;li&gt;Sleepwell&lt;/li&gt;
&lt;li&gt;Kurl-On&lt;/li&gt;
&lt;li&gt;Urban Ladder&lt;/li&gt;
&lt;li&gt;PepperFry&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We analysed pageSpeed Scores across all and prepared Charts which show that WakeFit stands tall.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flkyyg2gkdat7dab7z71n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Flkyyg2gkdat7dab7z71n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Scope
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;A lot has been done. But still a lot can be done. Some things that are yet to be tried:&lt;/li&gt;
&lt;li&gt;Trying SSR (Server-Side Rendering).&lt;/li&gt;
&lt;li&gt;Using HHVM instead of regular PHP to boost throughtput.&lt;/li&gt;
&lt;li&gt;Using LightHouse CI (Continuous Integration) to automate Audit checking in future as we build more.&lt;/li&gt;
&lt;li&gt;Using Varnish Cache at the Server or trying NGINX default cache.&lt;/li&gt;
&lt;li&gt;Using HTTP/2 server push?&lt;/li&gt;
&lt;li&gt;Utilizing Service workers for caching?&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  References:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://medium.com/dev-channel/javascript-loading-priorities-in-chrome-57c54cfa6672" rel="noopener noreferrer"&gt;https://medium.com/dev-channel/javascript-loading-priorities-in-chrome-57c54cfa6672&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.dev/lcp/" rel="noopener noreferrer"&gt;https://web.dev/lcp/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.nginx.com/blog/nginx-high-performance-caching/#CachingProcess" rel="noopener noreferrer"&gt;https://www.nginx.com/blog/nginx-high-performance-caching/#CachingProcess&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://web.dev/lighthouse-ci/" rel="noopener noreferrer"&gt;https://web.dev/lighthouse-ci/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>css</category>
      <category>webperf</category>
    </item>
  </channel>
</rss>
