<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ramy Rais on Medium]]></title>
        <description><![CDATA[Stories by Ramy Rais on Medium]]></description>
        <link>https://medium.com/@ramyrais?source=rss-d92140e2444------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*bmT139NFByWko3n1UiaVgw.jpeg</url>
            <title>Stories by Ramy Rais on Medium</title>
            <link>https://medium.com/@ramyrais?source=rss-d92140e2444------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 13:01:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramyrais/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Performance as a third party library]]></title>
            <link>https://medium.com/@ramyrais/performance-as-a-third-party-library-a4e19d857332?source=rss-d92140e2444------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4e19d857332</guid>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[speed]]></category>
            <category><![CDATA[web-vitals]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Ramy Rais]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 12:23:22 GMT</pubDate>
            <atom:updated>2023-08-31T12:23:22.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8OCvLbaIs3Ha8KtR" /><figcaption>Photo by <a href="https://unsplash.com/@mike_van_den_bos?utm_source=medium&amp;utm_medium=referral">Mike van den Bos</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><blockquote>Speed is the most important feature. If your application is slow, people won’t use it” — <a href="https://triple-networks.com/2011/12/06/10-golden-principles-of-successful-web-apps/">Fred Wilsons</a></blockquote><p>We all hate a loading screen that takes forever and we certainly know how frustrating it is to keep staring at a loading animation. I am sure we’ve all been there once. Hence, speed is something that every web application owner aims for.</p><p>Google provides <a href="https://web.dev/vitals/">guidelines</a> for web application owners on how to measure some quality signals like FCP (First Contentful Paint), LCP (Largest Contentful Paint), FID (First Input Delay). But what about the case where you are a third party in the website? What metrics do you need to monitor and how? Does using metrics like FCP and LCP make sense in this case?</p><p>In this article I would like to share my experience about measuring the performance of a third party script.</p><p>I will start by explaining the problem with common web vitals in this context. Then, I will introduce what metrics could be more relevant for the third party script. At the end, I will demonstrate how to measure and collect this data.</p><h3>Problem</h3><p>At the time I am writing this article, there are many resources on the internet demonstrating how to check your web application’s performance, and how third party scripts may be a source of problem. As an owner of a third party script, the <a href="https://web.dev/vitals/">web vitals</a> that Google provides are not useful metrics as you don’t own the web application. They indicate the performance of the whole application and not your script specifically. So in this case, if your script’s users complain that it is slow and it is causing performance issues to their website, then you need different metrics to validate the poor performance and analyse the causes. Now, let’s deep dive into what metrics may be relevant.</p><h3>Metrics</h3><p>As a third party script we start having effect on the page only when our script starts loading, that moment is our zero in the timeline of execution. We will call this metric <strong>script_loading_start</strong>. After that we will need the moment the script is done loading, we will call this one <strong>script_loading_end</strong>. We can identify how long it took for the script to download simply by doing <strong>script_loading_end — script_loading_start</strong>. Now we can validate complaints regarding script loading time. If someone says the script is only available after 5 seconds but it only started downloading after 4 seconds, then it is not really our fault.</p><p>At this point we know when our script started, we need to identify the moment we showed useful information to the user, this depends on the functionalities of the script. Only displaying some information to the user is different than having an interactive widget where it waits for user input. We will call it simply <strong>script_usable</strong>.</p><p>If our script is doing api calls, it is useful to know the response time of the different requests. While this is probably measured by the backend team, their measures are not really what the users perceive. The backend will measure the time the server needed to answer to a request without taking into account network latency. Similarly to the script loading time we will need 2 metrics that we will call, <strong>request_start</strong> and <strong>request_end</strong>.</p><p>These are the most common metrics I can think of, other metrics may be needed depending on the functionalities of the script. In the next section we will see how to collect the mentioned metrics.</p><h3>Measurement</h3><p>Fortunately for us the performance API provides all the tools we need.</p><p>For the first 2 metrics <strong>script_loading_start </strong>and <strong>script_loading_end</strong>, we need to use the performance resource timing interface to get data about when a script started and finished loading. The following code extracts multiple data on the script, we are interested in <strong>startTime</strong> which is <strong>script_loading_start</strong> and <strong>responseEnd</strong>which is <strong>script_loading_end</strong>. The variable YOUR_SCRIPT_URL<em> </em>needs to be the URL used to include the script in the page.</p><pre>const resource = performance.getEntriesByType(&#39;resource&#39;).<br>  filter(entry =&gt; entry.name.includes(YOUR_SCRIPT_URL))[0]</pre><p>The API provides more data. If you are interested in more details you can visit the official <a href="https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming">documentation</a>, the below picture sums it up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rzbzoCUcYKvAq1nr" /><figcaption><em>This figure illustrates the timing attributes defined by the </em><a href="https://www.w3.org/TR/navigation-timing-2/#dom-performancenavigationtiming"><em>PerformanceNavigationTiming</em></a><em> interface.</em></figcaption></figure><p>PS: for the <strong>request_start</strong> and <strong>request_end</strong> metrics, you can use the same code to get the data. You only need to filter with different URLs.</p><p>For The <strong>script_usable</strong>, we need to use the marking functionality of the performance API. You need to find the place in code where you will mark the script. A mark is used to collect the time when that part of your code was reached in the lifetime of the webapp. By using the function peformace.mark(UNIQUE_ID) we create a mark, then we can get the data of that mark using the following code performance.getEntriesByName(UNIQUE_ID). As you can see this is pretty simple from a code perspective, it is more a matter of choosing the right place to mark the code.</p><h3>Sending the metrics</h3><p>An easy way to send the metrics, probably to a backend service, is to use the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API">beacon API</a>, it is pretty straightforward.</p><pre>navigator.sendBeacon(URL, DATA);</pre><p>If your script is being used in many websites, you may need to be carefull about the huge volume of data. A sampling mechanism of metrics may be needed.</p><h3>Common pitfalls</h3><ul><li>Script execution time: You may notice that you have short script loading time but long script usable time, in this scenario it may be interesting to check the script’s execution time. As JS is async, it is possible that your script is done downloading but something else is blocking the main thread. In this scenario, it may seem that your execution time is high but it is not the case. You can add a marker to detect when your script started executing.</li><li>Missing data: There are <a href="https://developer.mozilla.org/en-US/docs/Web/API/Performance_API/Performance_data#managing_buffer_sizes">limits</a> of entries in the performance API. It is possible that you don’t get some data from some client websites as they may overload the buffer of the performance API.</li><li>Multiple calls to the same URL: it is possible that your script calls a backend with the same endpoint multiple times. You will get multiple resource entries, you have to be careful about the data you choose. One simple way to overcome this, is to use a URL fragment with a counter.</li></ul><h3>Example</h3><p>In this <a href="https://github.com/RamyRais/example-performance-as-third-party-script">github repo</a> I created 2 examples. The idea is to show some weather data using an open API. The first script (non interactive) has the location hardcoded, so it only gets the weather information for a certain city. The second example (interactive script) will wait for user’s input regarding the city in order to show the weather.</p><p>PS: the interaction is not really working, as i did not find a free API that provides weather information by city name 😅. But the main point about the performance and metrics is tackled.</p><h3>References</h3><ul><li><a href="https://www.w3.org/TR/navigation-timing-2/#processing-model">Navigation Timing Level 2</a></li><li><a href="https://developers.google.com/web/fundamentals/performance/navigation-and-resource-timing#dns_lookup">Assessing loading performance in the field with Navigation Timing and Resource Timing</a></li><li><a href="https://web.dev/user-centric-performance-metrics/">User-centric performance metrics</a></li><li><a href="https://css-tricks.com/breaking-performance-api/">Breaking Down the Performance API | CSS-Tricks</a></li><li><a href="https://blog.logrocket.com/how-to-practically-use-performance-api-to-measure-performance/">How to practically use Performance API to measure performance - LogRocket Blog</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4e19d857332" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Grit: what is it and why is it so important for success? A summary of Grit by Angela Duckworth]]></title>
            <link>https://medium.com/@ramyrais/grit-what-is-it-and-why-is-it-so-important-for-success-a-summary-of-grit-by-angela-duckworth-366e3a373aff?source=rss-d92140e2444------2</link>
            <guid isPermaLink="false">https://medium.com/p/366e3a373aff</guid>
            <category><![CDATA[deliberate-practice]]></category>
            <category><![CDATA[success]]></category>
            <category><![CDATA[grit]]></category>
            <category><![CDATA[book-summary]]></category>
            <category><![CDATA[nonfiction]]></category>
            <dc:creator><![CDATA[Ramy Rais]]></dc:creator>
            <pubDate>Wed, 13 May 2020 16:53:00 GMT</pubDate>
            <atom:updated>2020-05-13T16:53:00.925Z</atom:updated>
            <content:encoded><![CDATA[<p>Before we deep dive into the chapters of the book, I want to state its more important takeaways.</p><ul><li>Grit is the secret key to success and achievements.</li><li>Effort is more important than talent for achievements.</li><li>Paragons of grit have 4 psychological assets. interest, practice, purpose and hope.</li><li>Gritty people do more deliberate practice.</li><li>Grit can be learned and improved.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*yTpg8tVZL1v4mSXNcLYBHw.jpeg" /><figcaption>By <a href="https://www.flickr.com/photos/jackbigbox/10687379345">jackbigbox</a></figcaption></figure><h3><strong>What grit is and why it matters</strong></h3><p>Angela Duckworth argues in this book, that the secret of high achievers is <strong>grit</strong>. <strong>Grit</strong> is passion and perseverance for long-term goal(s).</p><p>The author presents anecdotes and statistical data supporting the idea that hard work and dedication impact the likelihood of success more than talent. The impact of effort on achievement is exponentially greater than talent. The best in their fields rise to the top because they relentlessly pursue their goals. This is where grit comes into play, as you are more passionate and persevering about your goal, you tend to make more effort to achieve them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*JBG8K_WrubwiSPJTnLZkGw.jpeg" /></figure><p>Unfortunately, people tend to have what is called the “naturalness bias” according to Chia-Jung Tsay’s <a href="https://hbr.org/2016/05/people-favor-naturals-over-strivers-even-though-they-say-otherwise">research</a>. When asked “what is more important to success, hard work or talent?”. People tend to answer hard work, but this is not their answer to explain someone’s success.</p><p>Duckworth introduces the grit scale used in her research, you can check your score using this <a href="https://angeladuckworth.com/grit-scale/">link</a>. Grit score is not a fixed value overtime, it can change as it is greatly influenced by life experience. This raises the question: Can we develop grit?<br>Research reveals grit paragon have 4 common psychological assets.</p><ul><li>Interest: To love what you are doing.</li><li>Capacity to practice: Being gritty is to resist complacency.</li><li>Purpose: the usefulness of what you are doing to others.</li><li>Hope: To keep going even when things are difficult.</li></ul><h3>Grow grit from the inside out</h3><p>After covering the main idea behind grit in the first part, Duckworth explores, in the following section, how it is possible to grow it. In this part we will explore how to grow grit using the psychological assets mentioned above.</p><ol><li><strong>Develop deep interest in something</strong>: Interest will not be found out somehow magically. Duckworth insists that a person should interact with the outside world and try different things before figuring out what they truly enjoy. Interest also needs to be developed proactively by doing things again and again.</li><li><strong>Deliberate practice</strong>: It is about setting a stretch goal and the full concentration and effort to achieve it, then setting the next stretch goal and repeating. It is important that a person seeks for informative feedback and reflects on his performance during deliberate practice.</li><li><strong>Find a purpose in what you do</strong>: Duckworth’s research revealed that gritty people tend to have a purpose. This purpose is developed like interest, a person needs to play an active role in developing and deepening it. Added to that, observing purposeful role models helps in finding your purpose. This will lead to a first revelation consisting in discovering a problem that needs solving, followed by a second revelation which is “You can make a difference”.</li><li><strong>Hope</strong>: In this context, it means the expectation that our own effort can improve one’s own future. According to Duckworth, this sense of hope comes from a growth mindset. A fixed mindset leads to pessimistic explanations of adversity, which in turn results in both giving up and avoiding challenges. Growth mindset leads to an optimistic explanation of adversity, which leads to perseverance and seeking out new challenges.</li></ol><p><strong>Note</strong>: There is a <a href="https://studentsuccess.unc.edu/files/2015/08/MINDSET-Quiz.pdf">quiz</a> developed by Carol Dweck to test if you have a growth mindset or fixed mindset.</p><h3>Growing grit from the outside in</h3><p>The last chapter is exploring how you grow grit from outside factors and how you can influence other people to be more gritty.</p><ol><li><strong>Parenting</strong>: Duckworth sees that the parents of grit paragon are demanding and supportive at the same time, this is called wise parenting, but wise parenting is not the only requirement. Parents need to model grittiness, they need to show passion and perseverance for their own long term goal in order to affect children’s grittiness. The other aspect of parenting is teaching. Studies show that teachers have an effect on children and they can help them develop grittiness by providing wise feedback.</li><li><strong>Extracurricular activities</strong>: Duckworth mentions the importance of extracurricular activities on kids, it helps them figure out their interests and get them in the process of practice to achieve better results. It basically sets up the children in the process to grow their grit from the inside out. It is important to mention that the effect of extracurricular activities on kids is not backed up by research.</li><li><strong>Culture</strong>: To build grit through influence of others you need to join an organisation, a team or a group known for hard work and perseverance. The longer people are part of a gritty culture, the more they adapt to its standard and values as their own.</li></ol><h3>Conclusion</h3><p>All in all, grit is passion and perseverance for long-term goals and it is an important value to succeed in what you are doing. Also grit is not something you are born with, rather an attitude you develop.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=366e3a373aff" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>