<?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: Adel Tahri</title>
    <description>The latest articles on DEV Community by Adel Tahri (@tahriadel).</description>
    <link>https://dev.to/tahriadel</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%2F1500%2Fb4fae383-55d8-404d-aa24-e94b89a6d3d0.jpg</url>
      <title>DEV Community: Adel Tahri</title>
      <link>https://dev.to/tahriadel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tahriadel"/>
    <language>en</language>
    <item>
      <title>Debugging WordPress Theme Load Performance with Chrome DevTool</title>
      <dc:creator>Adel Tahri</dc:creator>
      <pubDate>Sun, 24 Mar 2019 09:04:49 +0000</pubDate>
      <link>https://dev.to/tahriadel/debugging-wordpress-theme-load-performance-with-chrome-devtool-4960</link>
      <guid>https://dev.to/tahriadel/debugging-wordpress-theme-load-performance-with-chrome-devtool-4960</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;In this small article, I’m going to show you how I fix a small performance issue&lt;br&gt;
with WordPress theme that we are working on at&lt;br&gt;
&lt;a href="https://pixeldima.com/" rel="noopener noreferrer"&gt;PixelDima&lt;/a&gt;, showing you how to use the Chrome DevTools.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnkahlkptpuaqnne567a6.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnkahlkptpuaqnne567a6.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Debugging
&lt;/h3&gt;

&lt;p&gt;As I mentioned on the title I’ll use DevTool on &lt;a href="https://www.google.com/chrome/canary/" rel="noopener noreferrer"&gt;Chrome&lt;br&gt;
Canary&lt;/a&gt;, you can use the standard Chrome If&lt;br&gt;
you want.&lt;/p&gt;

&lt;p&gt;I’ll work on a local environment for that you can use &lt;a href="https://localbyflywheel.com/" rel="noopener noreferrer"&gt;Local by&lt;br&gt;
Flywheel&lt;/a&gt; to setup your WordPress.&lt;/p&gt;

&lt;p&gt;Let’s start Profiling and Reload the page to see the performance:&lt;/p&gt;

&lt;p&gt;1- Opening DevTools from Chrome’s main menu&lt;/p&gt;

&lt;p&gt;Open Chrome DevTools by clicking on the menu at the top right corner, then More&lt;br&gt;
&lt;em&gt;Tools *&amp;gt;&lt;/em&gt; Developer Tools*&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1dkfrk8sq5kwnxvw0ewb.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F1dkfrk8sq5kwnxvw0ewb.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;2 — Go to the &lt;strong&gt;Performance&lt;/strong&gt; tab.&lt;/p&gt;

&lt;p&gt;3 — Click on the &lt;strong&gt;reload&lt;/strong&gt; icon.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5fo3yfq77yeax33dddid.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5fo3yfq77yeax33dddid.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Looking at The performance profile
&lt;/h3&gt;

&lt;p&gt;Here is the performance profile of page load.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy15fsvtsf8zh040rt5zx.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fy15fsvtsf8zh040rt5zx.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Zoom into the red bar where the large “&lt;strong&gt;blocks&lt;/strong&gt;”&lt;/p&gt;

&lt;p&gt;As you can see below we can confirm this period of time was slow, the frame took&lt;br&gt;
&lt;code&gt;68.1 ms&lt;/code&gt; to execute, and ran at &lt;code&gt;15 FPS&lt;/code&gt; and CPU time &lt;code&gt;277.66&lt;/code&gt;.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftyxmo2q1o7u0tq6m3v64.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ftyxmo2q1o7u0tq6m3v64.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A red bar above the FPS is a warning that the frame rate dropped so low that it&lt;br&gt;
probably harmed the user’s experience.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To start an investigation the &lt;code&gt;Red&lt;/code&gt; bar above the &lt;strong&gt;FPS&lt;/strong&gt; graph. If you click on&lt;br&gt;
the record that has a &lt;strong&gt;Red triangle&lt;/strong&gt; on top right-hand you will get more&lt;br&gt;
ditties at the &lt;strong&gt;Summary tab&lt;/strong&gt;.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdtjdftl25ok0780zajlq.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdtjdftl25ok0780zajlq.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can say the children scripting is ticking &lt;code&gt;45.5 ms&lt;/code&gt;, so we must know&lt;br&gt;
which activities directly took up the most time in aggregate. DevTool is able to&lt;br&gt;
display activities during the selected portion of the recording.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2duz4aefx3ivq9omvn5w.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F2duz4aefx3ivq9omvn5w.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Above you can see that almost practically all of the time was spent executing&lt;br&gt;
the two calls &lt;code&gt;e.refrech&lt;/code&gt;on &lt;code&gt;vendors.min.js&lt;/code&gt; (JS file that contains all the&lt;br&gt;
scripts used on the theme ) and &lt;code&gt;Recalculate Style&lt;/code&gt; click on &lt;code&gt;e.refrech&lt;/code&gt; and you&lt;br&gt;
will get:&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgmqx2yrnlal1xp45xmdg.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fgmqx2yrnlal1xp45xmdg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;DevTools takes you to the exact point in code which triggered the event. As the&lt;br&gt;
code is minified, you should pretty print it.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnpqr4jo024hsiwry0lzw.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fnpqr4jo024hsiwry0lzw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I searched for “&lt;code&gt;data-anchor-target&lt;/code&gt;" on all JS files on the theme and I found&lt;br&gt;
that the file behind the slow is &lt;code&gt;skrollr.js&lt;/code&gt; we use it for the parallax images,&lt;br&gt;
but in this page, we did not use any parallax images.&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foethcq7qiqy6exqknmpq.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Foethcq7qiqy6exqknmpq.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best way to get exactly the code behind the slow frames on a big project is&lt;br&gt;
to filter the JS file and go for the custom JS code that we write.&lt;/p&gt;

&lt;p&gt;So in order to open the tree, you can hold Option (Mac) or Control+Alt (Windows,&lt;br&gt;
Linux) then click. ( Thanks to @ChromeDevTools )&lt;/p&gt;

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

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



&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa5nyxjiboh36qyguak71.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fa5nyxjiboh36qyguak71.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now after opening the tree activates I searched for &lt;code&gt;main.min.js&lt;/code&gt; which contain&lt;br&gt;
our custom JS, I opened it and as expected it goes directly into the code that&lt;br&gt;
runs the parallax ( &lt;em&gt;where we use Skrollr function&lt;/em&gt; ).&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5e5895cvrwwvvqcd07j0.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F5e5895cvrwwvvqcd07j0.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the code, you can see that we are calling &lt;code&gt;Skrollr&lt;/code&gt; without any condition&lt;br&gt;
which means it's running even if we did not use it. So in order to fix this, we&lt;br&gt;
must add a condition that test if the element &lt;code&gt;$(".parallax-background")&lt;/code&gt; exists&lt;br&gt;
before calling the Skrollr function.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Result After The Fix
&lt;/h3&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3dai9ri5xpw43jv5ipnt.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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3dai9ri5xpw43jv5ipnt.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this small fix, we don’t have the red bar anymore and we manage to save &lt;code&gt;25&lt;br&gt;
ms&lt;/code&gt; ( from &lt;code&gt;68 ms&lt;/code&gt; into &lt;code&gt;43 ms&lt;/code&gt; ) and now run at &lt;code&gt;23 FPS&lt;/code&gt;instead of &lt;code&gt;15 FPS&lt;/code&gt;&lt;br&gt;
with CPU time &lt;code&gt;247.06 ms&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sources:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://moderndevtools.com/lessons/11" rel="noopener noreferrer"&gt;https://moderndevtools.com/lessons/11&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference" rel="noopener noreferrer"&gt;https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>devtools</category>
      <category>wordpress</category>
      <category>debugging</category>
      <category>chrome</category>
    </item>
  </channel>
</rss>
