Only the first js chunk comes in via CDN?

Hi,

Since starting to use (and evaluate Netlify for our future purposes), I’ve noticed a strange behavior - only the first js chunk comes in via cloudfront (with a fairly consistent <200ms delay). The rest comes in “directly”, and ever so often the site load crawls since the subsequent js chunks take upto 4 - 8 seconds to come in.

The first chunk always has the form https://<>.cloudfront.net/bundles/<> while the remaining have the form /static/js/13.9e1a5fcf.chunk.js (ie the chunks created due to lazy loading etc). This is a React site.

Looking at this behavior and the HTTP response headers on each js chunk leads me to believe that subsequent chunks are not cached via a CDN. But that can’t be right, or?

  1. Am I correct with this above conclusion?
  2. Is this a feature or a bug? Or am I missing something else altogether?

PS: I tried searching thru the forums for something similar to this concern, but could not find. If there are other threads, please point me to them.

Thanks.

cloudfront URLs have nothing to do with caching as far as I know, though I might be wrong. When asset optimization is turned on in Netlify settings, the JS files that are present in the HTML files during the time of deploy get converted to cloudfront URLs even if they’re not modified at all.

So, if you can actually link to the website in which you’re seeing this problem, others can check this for you.

Site is https://www.maincross.net

So, as I can see, the chunk.js files are loaded dynamically using JS and they don’t really exist in the markup:

Thus the problem, I would say.

But why is that the problem? There’s no reason why all the chunks cant be cached and delivered via cloudfront, which is AWS CDN. Unless there’s a policy - and if so, can you pls point me to it so I can read further on it.

From what I know, Netlify only optimizes files that are listed in the HTML markup. Even if it optimises all JS files, I’m not sure how yours is being generated.

Also, on a side note, if your concern is that your files are not being served from CDN just because they’re not Cloudfront URLs, that’s not true. Cloudfront or not, your files are being served using a CDN. Cloudfront URLs are only for files that are processed by Netlify due to Asset Optimization turned on. This should not have an effect on speed.