<?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 Sheng Li on Medium]]></title>
        <description><![CDATA[Stories by Sheng Li on Medium]]></description>
        <link>https://medium.com/@shengli356?source=rss-d69e8a0a0a68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bAuVy1WlRl8h2Y8DlqIMpQ.jpeg</url>
            <title>Stories by Sheng Li on Medium</title>
            <link>https://medium.com/@shengli356?source=rss-d69e8a0a0a68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 19:14:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shengli356/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[Embrace React Code Splitting: A Comprehensive Guide to Enhance Performance and User Experience]]></title>
            <link>https://medium.com/@shengli356/embrace-react-code-splitting-a-comprehensive-guide-to-enhance-performance-and-user-experience-aabbdb459c8?source=rss-d69e8a0a0a68------2</link>
            <guid isPermaLink="false">https://medium.com/p/aabbdb459c8</guid>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[code-splitting]]></category>
            <dc:creator><![CDATA[Sheng Li]]></dc:creator>
            <pubDate>Sat, 01 Apr 2023 20:17:47 GMT</pubDate>
            <atom:updated>2023-04-01T20:18:20.293Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*2bMv3xORZbQYDgAa.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>In the ever-evolving world of web development, performance optimization plays a crucial role in delivering a seamless user experience. With feature-rich applications becoming the norm, it’s essential to find ways to enhance loading speed and overall performance. One such technique is code splitting, which has emerged as a powerful tool for React developers. In this comprehensive guide, we will delve into the concept of React code splitting, its benefits, and how to implement it in your applications without breaking a sweat.</p><p>What is React Code Splitting?</p><p>React code splitting is a technique that enables developers to divide their application into smaller, more manageable chunks of code. These smaller pieces, or “chunks,” are loaded on-demand, ensuring that users download only the necessary code for the current view. This approach results in faster initial loading times and improved overall performance, as the application doesn’t have to load the entire JavaScript bundle at once.</p><p>Benefits of Code Splitting:</p><ol><li>Improved Performance: By loading only the necessary chunks of code, applications start faster, consuming fewer resources and providing a better user experience.</li><li>Reduced Network Traffic: Smaller code bundles mean less data needs to be transferred over the network, reducing bandwidth usage and load times.</li><li>Easier Maintenance: Dividing your application into smaller, more focused pieces can make it easier to understand, maintain, and update.</li></ol><p>Getting Started with React Code Splitting:</p><p>React has made code splitting simple and straightforward, thanks to the built-in React.lazy() function and the Suspense component. These features allow developers to load components lazily, rendering a fallback content while the component is being fetched.</p><p>Here’s a step-by-step guide to implementing code splitting in a React application:</p><ol><li>Identify the Components to Split:</li></ol><p>First, determine which components can benefit from code splitting. Typically, these are the larger components or those not immediately needed when the application starts. Components that are conditionally rendered or only visible after user interaction are good candidates for code splitting.</p><ol><li>Use React.lazy():</li></ol><p>React.lazy() is a function that takes a function returning a dynamic import() statement as its argument. This dynamic import loads the specified component as a separate chunk, which is then fetched only when needed.</p><p>For example, let’s say we have a component called HeavyComponent that we want to load lazily:</p><pre>import React from &#39;react&#39;;<br><br>const HeavyComponent = React.lazy(() =&gt; import(&#39;./HeavyComponent&#39;));</pre><p>3. Wrap with Suspense:</p><p>Next, wrap the lazily-loaded component in a Suspense component. The Suspense component takes a fallback prop, which is the content to display while the component is being fetched.</p><pre>import React, { Suspense } from &#39;react&#39;;<br>import HeavyComponent from &#39;./HeavyComponent&#39;;<br><br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;header className=&quot;App-header&quot;&gt;<br>        {/* Other content */}<br>      &lt;/header&gt;<br>      &lt;main&gt;<br>        &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>          &lt;HeavyComponent /&gt;<br>        &lt;/Suspense&gt;<br>      &lt;/main&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>That’s it! Your application now utilizes code splitting and loads HeavyComponent only when it&#39;s required.</p><p>Handling Error Boundaries:</p><p>When implementing code splitting, it’s essential to handle potential errors, such as network failures or the component failing to load. You can achieve this by using an error boundary component.</p><p>An error boundary is a React component that catches JavaScript errors in its child component tree, logs those errors, and displays a fallback UI instead of the component that crashed.</p><p>Here’s an example of an error boundary component:</p><pre>import React, { Component } from &#39;react&#39;;<br><br>class ErrorBoundary extends Component {<br>  constructor(props) {<br>    super(props);<br>    this.state = { hasError: false };<br>  }<br><br>  static getDerivedStateFromError(error) {<br>    return { hasError: true };<br>  }<br><br>  componentDidCatch(error, errorInfo) {<br>    // You can log the error here, for example, using a logging service<br>    console.log(error, errorInfo);<br>  }<br><br>  render() {<br>    if (this.state.hasError) {<br>      // You can customize the fallback UI displayed when an error occurs<br>      return &lt;h1&gt;Something went wrong. Please try again later.&lt;/h1&gt;;<br>    }<br><br>    return this.props.children;<br>  }<br>}<br><br>export default ErrorBoundary;<br><br></pre><p>To use the error boundary component, simply wrap the `Suspense` component with it:</p><pre>import React, { Suspense } from &#39;react&#39;;<br>import ErrorBoundary from &#39;./ErrorBoundary&#39;;<br>import HeavyComponent from &#39;./HeavyComponent&#39;;<br><br>function App() {<br>  return (<br>    &lt;div className=&quot;App&quot;&gt;<br>      &lt;header className=&quot;App-header&quot;&gt;<br>        {/* Other content */}<br>      &lt;/header&gt;<br>      &lt;main&gt;<br>        &lt;ErrorBoundary&gt;<br>          &lt;Suspense fallback={&lt;div&gt;Loading...&lt;/div&gt;}&gt;<br>            &lt;HeavyComponent /&gt;<br>          &lt;/Suspense&gt;<br>        &lt;/ErrorBoundary&gt;<br>      &lt;/main&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now, if there’s an error while loading HeavyComponent, the error boundary will catch it and display the fallback UI, ensuring a graceful degradation of the application&#39;s user experience.</p><p>Route-based Code Splitting:</p><p>In many React applications, route-based code splitting is a common and effective approach to optimize performance. Using this technique, you can split your code based on the application’s routes, loading only the necessary components for the current view.</p><p>To implement route-based code splitting, follow these steps:</p><ol><li>Install the @loadable/component library, which provides an easy-to-use API for code splitting and works seamlessly with React Router:</li></ol><pre>npm install @loadable/component</pre><p>2. Update your route configuration to use the @loadable/component library:</p><pre>import React from &#39;react&#39;;<br>import { BrowserRouter as Router, Route, Switch } from &#39;react-router-dom&#39;;<br>import loadable from &#39;@loadable/component&#39;;<br><br>const Home = loadable(() =&gt; import(&#39;./components/Home&#39;));<br>const About = loadable(() =&gt; import(&#39;./components/About&#39;));<br>const Contact = loadable(() =&gt; import(&#39;./components/Contact&#39;));<br><br>function App() {<br>  return (<br>    &lt;Router&gt;<br>      &lt;Switch&gt;<br>        &lt;Route exact path=&quot;/&quot; component={Home} /&gt;<br>        &lt;Route path=&quot;/about&quot; component={About} /&gt;<br>        &lt;Route path=&quot;/contact&quot; component={Contact} /&gt;<br>      &lt;/Switch&gt;<br>    &lt;/Router&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now, each route’s component will be loaded lazily, improving the application’s performance by loading only the necessary code for the current view.</p><h3>Conclusion:</h3><p>React code splitting is a powerful technique that helps developers optimize the performance and user experience of their applications. By dividing your code into smaller, more manageable chunks, you can significantly reduce initial load times and improve overall application responsiveness. With the help of built-in features like React.lazy() and Suspense, as well as third-party libraries like @loadable/component, implementing code splitting in your React applications has never been easier. So, go ahead and embrace the power of code splitting to deliver lightning-fast, user-friendly applications to your users!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aabbdb459c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ClusterWatch Official Launch]]></title>
            <link>https://medium.com/@shengli356/clusterwatch-official-launch-8c77885de58b?source=rss-d69e8a0a0a68------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c77885de58b</guid>
            <category><![CDATA[cluster-monitoring]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[prometheus]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <dc:creator><![CDATA[Sheng Li]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 18:01:32 GMT</pubDate>
            <atom:updated>2023-03-14T18:13:12.481Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>Kubernetes clusters have become the go-to container orchestration tool for modern cloud-native applications. However, as the size of a cluster grows, so do the challenges associated with monitoring its health and performance. In order to ensure a successful deployment, it is essential to be able to monitor the state of the cluster, detect issues, and take corrective actions in real-time. Without adequate monitoring tools, cluster administrators are unable to effectively manage their clusters, leading to outages, application downtime, and other critical issues.</p><p>If you have deployed and managed a Kubernetes cluster, you have probably seen something like this before:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*2pnzh45RThjbaBurQ0DbZQ.png" /></figure><p>This is without question the fastest, simplest way to capture basic cluster metrics in real time. But in a world where container orchestration can be the focus of an entire career, these basic statistics could never be enough to satisfy the relentless quest for optimization.</p><p>As the containers grow, and pods and services become more clustered, the inter-relationship of these individual deployable units within the cluster can get pretty convoluted very quickly. This would inevitably cause tremendous headache when it comes to troubleshoot, debug, optimize and scale your application. To solve this problem, our team of developers have created our own solution, ClusterWatch.</p><h3><strong>Solution</strong></h3><p>ClusterWatch is an OpenSource Product that provides a comprehensive solution to the challenges associated with Kubernetes cluster monitoring. By leveraging Kubernetes orchestration for optimal scalability and efficiency, ClusterWatch is able to provide real-time monitoring of the various architectural layers of the cluster. This includes information on nodes, pods, services, and other critical components of the cluster. With this information, administrators can quickly detect and respond to any issues, such as node or pod failures, before they cause major problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*fN3IFIHoy2T0vFup8qaJWw.png" /></figure><p>In addition to its comprehensive monitoring capabilities, ClusterWatch also provides an automated configuration process for Prometheus and Grafana, incorporating them into the Kubernetes cluster. With just a few clicks, users can set up their Prometheus and Grafana instances, and seamlessly integrate them into their Kubernetes cluster, making it easy to monitor and optimize the performance of their applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*nJEocGuF9GbkqYXEWZ25Dg.png" /></figure><p>Users can also set up custom alerts for any metrics they are interested in tracking, and these alerts can be viewed on the Alert Manager page view. This makes it easy for administrators to stay on top of any issues that may arise and take corrective action in real-time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*xxwjJdm5YcCxn2DyHfIm5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*dTu2WnsCanBRKQAfs_saGQ.png" /></figure><p>Built upon these powerful features, ClusterWatch provides a single view point for users to access all the information they need about their cluster’s health and performance. The interactive and responsive dashboard provides a comprehensive overview of the cluster, including real-time metrics on nodes, pods, services, and other critical components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JdNRoAakTI_0apNInzDqXw.png" /></figure><p>To summarize, ClusterWatch is a powerful open-source tool that provides real-time monitoring and management of Kubernetes clusters. With its automated configuration process, comprehensive monitoring capabilities, and user-friendly dashboard, ClusterWatch is an ideal solution for organizations that want to ensure the health and performance of their Kubernetes-based applications.</p><h3><strong>Get Started with ClusterWatch</strong></h3><p>STEP 1: CLONE THE REPO:</p><pre>git clone https://github.com/oslabs-beta/ClusterWatch.git</pre><p>STEP 2: INSTALL DEPENDENCIES:</p><pre>npm install</pre><p>STEP 3: START A KUBERNETES CLUSTER:</p><ul><li>Be sure to have your Kubernetes cluster up and running before the start of the application.</li><li>If you don’t have a cluster and would like test the application, install docker and use Minikube to get started. <a href="https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/">https://kubernetes.io/docs/tutorials/kubernetes-basics/create-cluster/cluster-intro/</a></li></ul><p>STEP 4: START THE APPLICATION:</p><pre>npm run dev</pre><p>STEP 5: INSTALL REDIS GLOBALLY:</p><p><em>We use Redis as our caching middleware to improve data retrieving speed, resulting in better real-time monitoring experience.</em></p><pre>brew install redis</pre><p>STEP 6: Navigate to : ‘http:/localhost8080’:</p><p><em>You should now be redirected to the setup page of the web app. If it’s your first time configuring your cluster, do the following setup steps:</em></p><ul><li>If you do not have the prometheus-kube-stack helm chart, (which inlcudes kube-state-metrics, node-exporter, and grafana), utilize the <strong>Setup Prometheus</strong> button to download, update, and install the repos. Note: this step can take a moment, don’t worry.</li><li>To deploy Grafana in your cluster, use the <strong>Setup Grafana</strong> button to apply our custom Grafana configurations.</li><li>If you have used our application before, press the <strong>Start Port Forwarding</strong> button and monitor away!</li><li>Keep in mind that the application utilizes local ports which must not be occupied on your machine:<br> — 3000: API Server<br> — 8080: Client Server<br> — 3001: Grafana<br> — 9090: Prometheus<br> — 9093: Alert Manager<br> — 6379: Redis</li></ul><h3><strong>Get Involved</strong></h3><p>You can check out ClusterWatch on our <a href="https://github.com/oslabs-beta/ClusterWatch">Github</a> or by visiting our <a href="http://clusterwatch.io/">website</a> where you’ll find everything you need to get it up and running. Feel free to submit any issues or contribute as a fellow developer to the open source product on Github.</p><p>Follow or check in with the ClusterWatch creators:</p><ul><li>Sheng Li [<a href="https://www.linkedin.com/in/sheng-li-3537783a/">LinkedIn</a>] | [<a href="https://github.com/shengli356">Github</a>]</li><li>Kevin Hendrix [<a href="https://www.linkedin.com/in/kevin-hendrix-sw?trk=profile-badge">LinkedIn</a>] | [<a href="https://github.com/khendrix12">Github</a>]</li><li>Mushrath Choudhury [<a href="https://www.linkedin.com/in/mushrathchoudhury/">LinkedIn</a>] | [<a href="https://github.com/mushrathc">Github</a>]</li><li>Jordy Gonzalez [<a href="https://www.linkedin.com/in/jordy-gonz%C3%A1lez-a0139524a/">LinkedIn</a>] | [<a href="https://github.com/JordyGonza">Github</a>]</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c77885de58b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>