#Is there any difference in using static files from the /public folder vs using it as a component per

1 messages · Page 1 of 1 (latest)

muted tree
#

Is there any difference in using static files from the /public folder vs using it as a component performance-wise?

dreamy juncoBOT
#

Hi @muted tree. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, there are differences in using static files from the /public folder versus using them as components in Next.js, and these differences can impact performance.

When you use static files from the /public folder, these files are served directly by Next.js. They can be cached by CDN providers for efficient delivery, and they can be accessed from your code starting from the base URL (/). However, only assets that are in the public directory at build time will be served by Next.js. Files added at request time won't be available. If you need persistent file storage, you might need to use a third-party service like AWS S3 (source (https://nextjs.org/docs/app/building-your-application/optimizing/static-assets)).

On the other hand, when you use built-in components in Next.js, these components come with a variety of built-in optimizations designed to improve your application's speed and Core Web Vitals. For example, the Image Component optimizes images for performance by lazy loading and automatically resizing images based on device size. The Link Component prefetches pages in the background for faster and smoother page transitions. The Script Component gives you control over loading and execution of third-party scripts (source (https://nextjs.org/docs/pages/building-your-application/optimizing)).

Therefore, while using static files from the /public folder can be straightforward and efficient for serving static assets, using built-in components can provide additional performance optimizations. The best approach depends on your specific use case and performance requirements.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: