Support Forums

What is the criteria netlify take in when deciding whether to cache in cloud-front (CDN)?

The project that I am working on uses Webpack to bundle it’s resources and the bundle outputs 10+ JS files and other files as well. But only one file from these files are being cached in cloud-front CDN the other are not. Even though I have enabled Asset optimisation for everything from the build settings and also used cacheGroup (Webpack). Is there any way I cache the whole files in cloud-front CDN ?. What is the criteria being used to cache these files ?

Hi @n4nagappan,

I believe I’ve already replied to this in your helpdesk ticket, but here’s it quoted:

Netlify CDN is not equal to Cloudfront. Kindly don’t confuse the two. All the static assets less than 1 MB in size are generally served via the Netlify CDN. The CDN automatically caches the files once its requested and once it’s no longer being requested as much, it’s dropped out of the cache.

Cloudfront is the CDN for assets processed by Asset optimization. Any file modified by Asset optimization is served through Cloudfront, but that doesn’t mean the ones that are not processed are not served via a CDN.

To add to this, Netlify will only process the assets mentioned in your HTML files. The JS files should have references inside the HTML files for Netlify to be able to detect and process them.

1 Like

Thank you for responding, Can you give some more clarity. So there are two types of CDN in netlify:-

  1. Netlify CDN
  2. Cloudfront

If that is the case everything mentioned in the HTML file will be added to cloud-front and rest to netlify CDN. One more thing I am worried about is that if there are multiple JS files, will it all be combined into one ?

Hi, @n4nagappan. The cloudfront URLs occur when asset optimization is used in post processing:

Any files which are modified by the post processing get a Cloudfront URL. Unmodified content will have URLs under the custom domain or the site subdomain under netlify.app (if no custom domain is used).

You can find those settings under Site Name > Settings > Build & deploy > Post Processing in the web UI.

If there are other questions about this, please let us know.