<?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: Diwaker Singh</title>
    <description>The latest articles on DEV Community by Diwaker Singh (@diwakersurya).</description>
    <link>https://dev.to/diwakersurya</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%2F238133%2F7025c2cd-166d-4c04-b2e2-2efbfe36bc40.png</url>
      <title>DEV Community: Diwaker Singh</title>
      <link>https://dev.to/diwakersurya</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/diwakersurya"/>
    <language>en</language>
    <item>
      <title>Webpack to Rspack: A Deep Dive Into Our Build Time Breakthrough</title>
      <dc:creator>Diwaker Singh</dc:creator>
      <pubDate>Sun, 20 Jul 2025 06:16:43 +0000</pubDate>
      <link>https://dev.to/diwakersurya/webpack-to-rspack-a-deep-dive-into-our-build-time-breakthrough-3ih</link>
      <guid>https://dev.to/diwakersurya/webpack-to-rspack-a-deep-dive-into-our-build-time-breakthrough-3ih</guid>
      <description>&lt;h2&gt;
  
  
  1. Why We Migrated
&lt;/h2&gt;

&lt;p&gt;We maintain a large, multi-entrypoint Single Page Application (SPA) with a custom router and integrated micro-frontends via Module Federation. With over 11 independent entry bundles and full CI pipelines, &lt;strong&gt;build performance&lt;/strong&gt; had become a major bottleneck — especially with Webpack.&lt;/p&gt;

&lt;p&gt;Our main goal: &lt;strong&gt;dramatically reduce build time&lt;/strong&gt; without touching bundle size or runtime behavior. Rspack promised faster builds with familiar Webpack compatibility, and it delivered — but not without a few surprises.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Migration Plan and Scope
&lt;/h2&gt;

&lt;p&gt;We opted for an &lt;strong&gt;all-at-once migration&lt;/strong&gt; rather than phasing. This included:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Replacing Webpack with Rspack in all configs.&lt;/li&gt;
&lt;li&gt;Moving from &lt;code&gt;webpack.config.js&lt;/code&gt; to an array-based &lt;code&gt;rspack.config.js&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Updating all build/development scripts to use Rspack CLI.&lt;/li&gt;
&lt;li&gt;Ensuring all CI/CD pipelines, microfrontends, and chunk-loading logic remained intact.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rspack supports exporting an array of configs. Here's our &lt;code&gt;rspack.config.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./rspack/agency-admin.config.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./rspack/surveys.config.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./rspack/server.config.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each config builds independently in parallel — ideal for our multi-app setup.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Config Refactor: Before and After
&lt;/h2&gt;

&lt;p&gt;Our configs are modular: each specific app config extends a shared &lt;code&gt;base.config.js&lt;/code&gt; and &lt;code&gt;webapp.config.js&lt;/code&gt;. Here's how we structured a few key parts.&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Example: &lt;code&gt;agency-admin.config.js&lt;/code&gt; Highlights
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DEVELOPMENT&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scripts/engage/[name].js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scripts/engage/[name]/[contenthash].js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;chunkFilename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DEVELOPMENT&lt;/span&gt;
    &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scripts/engage/[name].chunk.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scripts/engage/[name].chunk/[contenthash].js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Module Federation&lt;/strong&gt; was preserved using Rspack’s &lt;code&gt;ModuleFederationPluginV1&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Asset stats were written using our custom &lt;code&gt;AssetManifestPlugin&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ Server Config (&lt;code&gt;server.config.js&lt;/code&gt;)
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Uses &lt;code&gt;target: 'node'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;externals&lt;/code&gt; configured with &lt;code&gt;webpack-node-externals&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Critical remotes loaded dynamically via module federation&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Plugin &amp;amp; Loader Compatibility
&lt;/h2&gt;

&lt;p&gt;Most Webpack loaders worked out of the box with minimal rewiring. However:&lt;/p&gt;

&lt;h3&gt;
  
  
  🛠️ Custom Plugin: &lt;code&gt;AssetManifestPlugin&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;We retained a hand-written plugin that generates a stats manifest JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;compiler&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;hooks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;tapPromise&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pluginName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;statsJson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;stats&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toJson&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;entrypoints&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;chunks&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;writeFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;filepath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;statsJson&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No changes were required to make it work with Rspack — a good sign of API stability.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Performance Gains
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Metric&lt;/th&gt;
&lt;th&gt;Webpack&lt;/th&gt;
&lt;th&gt;Rspack&lt;/th&gt;
&lt;th&gt;Gain&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Full Build&lt;/td&gt;
&lt;td&gt;1032.47 s&lt;/td&gt;
&lt;td&gt;312.92 s&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;~70% ↓&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The improvement was immediate, both locally and on CI (Jenkins). No changes were required in CI jobs — we simply swapped out the CLI in &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Gotchas
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ⚠️ &lt;code&gt;chunkhash&lt;/code&gt; Collision in S3 Artifacts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;We store all built assets in S3 using &lt;code&gt;[chunkhash]&lt;/code&gt; filenames.&lt;/li&gt;
&lt;li&gt;After the switch to Rspack, a few files generated the &lt;strong&gt;same chunkhash&lt;/strong&gt; as previous Webpack builds — but with incompatible runtime formats.&lt;/li&gt;
&lt;li&gt;Because we don't delete old artifacts, our CDN served a &lt;strong&gt;Webpack-built file&lt;/strong&gt; instead of the new one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  ✅ Fix:
&lt;/h4&gt;

&lt;p&gt;Switched from:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name].[chunkhash].js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[name].[contenthash].js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This made the hashing content-aware and eliminated the risk of mismatched builds.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚠️ &lt;code&gt;ContextReplacementPlugin&lt;/code&gt; Shim Removed
&lt;/h3&gt;

&lt;p&gt;During our initial POC, Rspack lacked support for &lt;code&gt;ContextReplacementPlugin&lt;/code&gt;, which we relied on in Webpack. We wrote a custom shim to mimic it.&lt;/p&gt;

&lt;p&gt;By the time we fully migrated, &lt;strong&gt;Rspack had added support&lt;/strong&gt;, allowing us to delete the shim and simplify the config.&lt;/p&gt;




&lt;h3&gt;
  
  
  ⚠️ Runtime Global Clashes
&lt;/h3&gt;

&lt;p&gt;Rspack does not default &lt;code&gt;chunkLoadingGlobal&lt;/code&gt; like Webpack. Without setting this explicitly, chunk runtime globals could clash — especially important in our microfrontend setup.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;output&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;chunkLoadingGlobal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rspackChunkLoadingGlobal&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  7. Testing, Tooling, and Integration
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;No changes were needed to our Flow, Jest, or E2E tests.&lt;/li&gt;
&lt;li&gt;Linting worked fine with &lt;code&gt;eslint-import-resolver-webpack&lt;/code&gt; pointing to &lt;code&gt;rspack.config.js&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Tools like Sentry sourcemaps, Webpack Bundle Analyzer, and custom loaders worked without modification.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CI (Jenkins) required &lt;strong&gt;no pipeline changes&lt;/strong&gt;. A simple script swap from &lt;code&gt;webpack&lt;/code&gt; to &lt;code&gt;rspack&lt;/code&gt; did the job.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Final Thoughts
&lt;/h2&gt;

&lt;p&gt;This was a high-impact migration that paid off in less than a week. Here’s what worked for us:&lt;/p&gt;

&lt;p&gt;✅ Migrating all apps at once to avoid hybrid states&lt;br&gt;&lt;br&gt;
✅ Ensuring S3 hash collisions were handled early&lt;br&gt;&lt;br&gt;
✅ Relying on plugin parity as Rspack matured&lt;/p&gt;




&lt;h2&gt;
  
  
  9. What's Next?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Investigating &lt;code&gt;Rsdoctor&lt;/code&gt; for further cold build diagnostics&lt;/li&gt;
&lt;li&gt;Possibly rewriting one legacy plugin using Rspack’s newer APIs&lt;/li&gt;
&lt;li&gt;We currently use Babel to strip Flow types and rely on multiple Babel plugins.
Moving to SWC would’ve touched a large surface area — so we deferred it.&lt;/li&gt;
&lt;li&gt;Similarly, we stayed with our PostCSS plugin stack for CSS processing and didn’t switch to Lightning CSS, 
prioritizing migration safety over marginal gains.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Rspack is ready for real-world use&lt;/strong&gt; — and for performance-obsessed frontend teams, it’s already a game changer.&lt;/p&gt;




&lt;h2&gt;
  
  
  Should You Migrate?
&lt;/h2&gt;

&lt;p&gt;Here’s how we’d answer it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Are your Webpack build times &amp;gt;10 minutes?&lt;/li&gt;
&lt;li&gt;✅ Do you have multiple independent apps or entrypoints?&lt;/li&gt;
&lt;li&gt;✅ Are you not relying on niche Webpack plugins with no Rspack equivalent?&lt;/li&gt;
&lt;li&gt;✅ Do you want a faster build with minimal rewrite risk?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If so, Rspack is a strong candidate. You don’t need to switch to SWC or Lightning CSS. We didn’t — and it still paid off.&lt;/p&gt;




&lt;h2&gt;
  
  
  Thanks for Reading
&lt;/h2&gt;

&lt;p&gt;If this migration helped you, or if you’re considering a similar move, we’d love to hear from you. Feel free to drop questions or share your experience in the comments.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Interested in how our design system tooling or MCP integrations evolve from here? Follow along or check the repo links soon.&lt;/em&gt; ✌️&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>webpack</category>
      <category>rspack</category>
    </item>
    <item>
      <title>Dynamic content in Github Profile Readme</title>
      <dc:creator>Diwaker Singh</dc:creator>
      <pubDate>Tue, 28 Jul 2020 17:06:06 +0000</pubDate>
      <link>https://dev.to/diwakersurya/dynamic-content-in-github-profile-readme-6i4</link>
      <guid>https://dev.to/diwakersurya/dynamic-content-in-github-profile-readme-6i4</guid>
      <description>&lt;p&gt;There is a new thing in the market called Github readme profile. If you are not aware of what it is, please read from &lt;a href="https://https://www.aboutmonica.com/blog/how-to-create-a-github-profile-readme" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I came to know about how people are doing really amazing things with github profiles and wanted to do something cool myself.&lt;/p&gt;

&lt;p&gt;The idea was to create an image dynamically and show it in github profile. I started with creating and express server on glitch.me and creating a route &lt;code&gt;/image&lt;/code&gt; which will serve the image. &lt;/p&gt;

&lt;p&gt;Dynamically creating images on node was easy using npm module canvas. More info about it &lt;a href="https://www.npmjs.com/package/canvas" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I ended up with following code for handling &lt;code&gt;/image&lt;/code&gt; route on the express server.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/* width and height of canvas*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1200&lt;/span&gt; 
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;630&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createCanvas&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="cm"&gt;/* random background color*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bgColor&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;getRandomColor&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;bgColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillRect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;width&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;height&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/* setting the font and text alignment*/&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bold 70pt Menlo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textAlign&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;center&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textBaseline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;top&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="cm"&gt;/* getting randome message if random language*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomIndex&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nf"&gt;getRandomInt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;language&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="nx"&gt;randomIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;language&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;textWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;measureText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt;
&lt;span class="cm"&gt;/*drawing text on canvas*/&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;170&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bold 15pt Menlo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`(&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;language&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;)`&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;280&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#fff&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;font&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bold 30pt Menlo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fillText&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;diwakersurya&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;540&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="cm"&gt;/* loading image from github url*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;myimg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;loadImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://avatars3.githubusercontent.com/u/7386665?s=400&amp;amp;u=aaff658cd860d5f886775a293c58e73fa57e7bf9&amp;amp;v=4&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;arc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;clip&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;drawImage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;myimg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;530&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;450&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;myimg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;width&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;myimg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;height&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="cm"&gt;/*sending as response to client*/&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;buffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;canvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toBuffer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;contentType&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;image/jpeg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;buffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What we are doing in this code basically is creating a canvas on express server and attaching a bunch of text/images in the&lt;br&gt;
canvas and finally sending it to client as an image.&lt;/p&gt;

&lt;p&gt;Once the server is up and running, We need to make following changes to the readme.md file.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;![](https://image-serv.glitch.me/image)  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;If you are familier with markdown, you know that this line loads an image from url &lt;code&gt;https://image-serv.glitch.me/image&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Thats it. The result will be something like this&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk9eppunqdb1m5rou3ruc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fk9eppunqdb1m5rou3ruc.png" alt="my-github-profile-readme" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once I saved my github profile readme and reloaded the page, The image started showing up as expected. But on reloading the page, I was unable to get new image with changed color and message.As it turned out, github was caching the image once loaded and using the cached image url in the readme. I tried different ways to overcome this issue but couldn't.&lt;/p&gt;

&lt;p&gt;Today I tried out again and turns out that github has removed caching of images. Refreshing the page gives me an image with new message and color.&lt;/p&gt;

&lt;p&gt;Checkout my profile &lt;a href="https://github.com/diwakersurya" rel="noopener noreferrer"&gt;https://github.com/diwakersurya&lt;/a&gt; and try refreshing the page.&lt;/p&gt;

&lt;p&gt;Since the image implementation is on server, there are definately infinite possibilities to think of. &lt;/p&gt;

&lt;p&gt;Github Profile Project:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/diwakersurya" rel="noopener noreferrer"&gt;
        diwakersurya
      &lt;/a&gt; / &lt;a href="https://github.com/diwakersurya/diwakersurya" rel="noopener noreferrer"&gt;
        diwakersurya
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      My readme profile
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/78cc11869dcfc552fbd54b0f58d6b29ed1629242778bc2643fd03ed0a7c443d8/68747470733a2f2f696d6167652d736572762e676c697463682e6d652f6769746875623f757365723d646977616b65727375727961"&gt;&lt;img src="https://camo.githubusercontent.com/78cc11869dcfc552fbd54b0f58d6b29ed1629242778bc2643fd03ed0a7c443d8/68747470733a2f2f696d6167652d736572762e676c697463682e6d652f6769746875623f757365723d646977616b65727375727961" alt=""&gt;&lt;/a&gt;&lt;/p&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;                     ⚡ Fun fact: * Refresh page to change the message language and background color. *
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;

  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/diwakersurya/diwakersurya" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;References:&lt;br&gt;
&lt;a href="https://flaviocopes.com/canvas-node-generate-image/" rel="noopener noreferrer"&gt;https://flaviocopes.com/canvas-node-generate-image/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/Automattic/node-canvas" rel="noopener noreferrer"&gt;https://github.com/Automattic/node-canvas&lt;/a&gt;&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/52940095/how-to-style-images-in-a-canvas" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/52940095/how-to-style-images-in-a-canvas&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.solosophie.com/how-to-say-hello-in-50/" rel="noopener noreferrer"&gt;https://www.solosophie.com/how-to-say-hello-in-50/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>beginners</category>
      <category>javascript</category>
      <category>node</category>
    </item>
  </channel>
</rss>
