<?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: Sohan Ram</title>
    <description>The latest articles on DEV Community by Sohan Ram (@sohan_ram_9feae12aeb49abc).</description>
    <link>https://dev.to/sohan_ram_9feae12aeb49abc</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%2F3541456%2F0f6dd4ad-31a4-4991-ba5d-6b66fe185968.jpg</url>
      <title>DEV Community: Sohan Ram</title>
      <link>https://dev.to/sohan_ram_9feae12aeb49abc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sohan_ram_9feae12aeb49abc"/>
    <language>en</language>
    <item>
      <title>Why React dynamic import file (~3.7 KB) take 650 ms on first load but only 45 ms on refresh with AWS S3 + CloudFront?</title>
      <dc:creator>Sohan Ram</dc:creator>
      <pubDate>Wed, 01 Oct 2025 11:18:36 +0000</pubDate>
      <link>https://dev.to/sohan_ram_9feae12aeb49abc/why-react-dynamic-import-file-37-kb-take-650-ms-on-first-load-but-only-45-ms-on-refresh-with-4m30</link>
      <guid>https://dev.to/sohan_ram_9feae12aeb49abc/why-react-dynamic-import-file-37-kb-take-650-ms-on-first-load-but-only-45-ms-on-refresh-with-4m30</guid>
      <description>&lt;p&gt;I have a React app deployed on &lt;strong&gt;AWS S3 + CloudFront&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;One of my routes uses a &lt;strong&gt;dynamic import&lt;/strong&gt; (&lt;code&gt;import()&lt;/code&gt;), and the corresponding JS chunk is very small (~3.7 KB).&lt;/p&gt;

&lt;p&gt;On the &lt;strong&gt;first load&lt;/strong&gt;, the request for this file takes about &lt;strong&gt;650 ms&lt;/strong&gt;, but if I refresh the page immediately afterward, it only takes about &lt;strong&gt;45 ms&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here’s the request and response details from Chrome DevTools for the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Request URL: https://admin.simprosysapis.com/assets/RolesList-DVgRFD0k.js
Request Method: GET
Status Code: 200 OK
Remote Address: 18.66.57.77:443
Referrer Policy: strict-origin-when-cross-origin
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Response headers
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cache-control: max-age=3600, must-revalidate
content-encoding: br
content-type: text/javascript
server: SimprosysAPI
via: 1.1 ...cloudfront.net (CloudFront)
x-cache: Miss from cloudfront
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Request headers
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accept-encoding: gzip, deflate, br, zstd
cache-control: no-cache
pragma: no-cache
user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  My questions
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Why does a 3.7 KB file take ~650 ms to load the first time?&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Is this mostly TLS/handshake + CloudFront latency rather than file size?&lt;/li&gt;
&lt;li&gt;Is the &lt;code&gt;x-cache: Miss from cloudfront&lt;/code&gt; header responsible?&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Why does it become so much faster (~45 ms) on refresh?&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Is the browser using &lt;strong&gt;disk/memory cache&lt;/strong&gt; or a &lt;strong&gt;CloudFront cached copy&lt;/strong&gt;?&lt;/li&gt;
&lt;/ul&gt;

&lt;ol&gt;
&lt;li&gt;Is there a way to improve the &lt;strong&gt;first load time&lt;/strong&gt; for these small dynamic chunks (e.g., preloading, prefetching, or CloudFront settings)?&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  What I tried
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Checked headers: &lt;code&gt;content-encoding: br&lt;/code&gt; confirms compression is working.&lt;/li&gt;
&lt;li&gt;Cache headers look reasonable (&lt;code&gt;max-age=3600&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Behavior is consistent across multiple builds.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Expected / Desired
&lt;/h3&gt;

&lt;p&gt;I want to understand if this latency difference is &lt;strong&gt;normal&lt;/strong&gt; for CloudFront + S3 dynamic imports, and whether I can optimize the first-load latency further.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>aws</category>
      <category>devops</category>
      <category>react</category>
    </item>
  </channel>
</rss>
