Search code examples
reactjsperformanceoptimizationcdnimage-load

Images loads faster if servced from local than CDN


I am using create-react-app CLI to build my application. What I noticed is that the images take longer time to load from CDN than if it is loaded from the local assets folder residing in the src folder. But everybody says that CDN is faster which I am not noticing. The same image takes 200ms to load through CDN whereas 4ms when it is from a local folder.

What do you think is the best way?


Solution

  • Files that are local will always be faster. But only for the local machine, think about it you are hosting and using the site locally and the image files are also on the machine. You have no external calls to outside sources. You could work with no internet connection.

    Now if you use a CDN that needs the internet, it will go and fetch that file for you. Developing locally that will be slower. But as soon as your app is being used by clients they will need that image, getting it from your server will work, but it may be slower.

    The power of a CDN is that they have are a network, they have redundancy, caching, and they have instances all over the world. It will take load of your server itself.