CDN VS Local in Laravel

When you’re using Laravel, you most likely will need additional CSS or JavaScript libraries. The way you can do this is either by CDN or downloading the library and add it to your project directory. But, which one should you use?

It depends on your preference. They each have their pros and cons, but the difference won’t affect your project too much.

We’ll dive into each of those methods

CDN

A Content Delivery Network (CDN) is a geographically distributed network of servers and their data centers that help in content distribution to users with minimal delay (Source : CDNetworks).

Basically, the files you need will be loaded from the server nearest to you, thus faster loading speed. Also, caching from CDN also helps with your page speed.

Pros :

  • Easy to add
  • Faster loading time

Cons :

  • When developed locally, you must have internet connection
  • Depends on the CDN provider (if it is down, you can’t use the library)

Local

Adding library locally means you download the files and put it inside your project and then reference it with either link or script tag depending on the file.

Pros :

  • Can be developed locally without internet connection
  • Independent of the CDN provider
  • Better performance if your web is simple

Cons :

  • Needs more steps to add if compared to CDN
  • Needs more memory because files are added to your project

Conclusion

It all comes back to preference, but I personally prefer using CDN since it’s way simpler to use and has speed benefits. CDN itself is made to accommodate modern and more complex websites. So, I prefer it.

For another topic on Laravel, check out Which Laravel Version Should You Use.

Now that you understand more about Laravel, if you’re looking for where to host your Laravel App, I recommend Cloudways. It is compatible, fast, reliable and has a specific option for Laravel. There are also tons of resources about Laravel hosting on Cloudways. Go ahead and check it out!

If you’re looking to refresh your PHP skill, you can try Codecademy’s free PHP course. Go ahead and check out the syllabus to see if it fits you. If you’re interested, go and try it for free!

If you are interested to learn more, you can learn here. They did an amazing job in explaining CDN.

Now, which one do you prefer?

Leave a Comment