-2

I heard that requesting many single Javascript files in a HTML page is slow, so I wonder if it is faster to bake all those files directly into the HTML code using a build system or does the page load quicker when all JS files were merged into one file that than is requested by the HTML document?

I'm only considering the initial loading time, as caching obviously would equalise any difference.

user11914177
  • 885
  • 11
  • 33
  • It is combination of both. You want to have essential javascript loaded as soon as possible and you don't want to do extra calls you don't need to do. This problem (partially) disappears with http/2. You can use defer attribute in your script tag to defer execution of js you don't need to execute right away https://www.w3schools.com/tags/att_script_defer.asp – digitalniweb Dec 27 '21 at 16:16
  • So is there any difference between the two methods I listed? – user11914177 Dec 27 '21 at 16:25
  • 1
    I just wrote the differences. But I guess you are asking if any is better than the other. I think one might be better in some situations and other in other situation. In reality the differences will be so negligible this question doesn't even need to be asked. Just do what you want. Tomatoes, tomatoes. – digitalniweb Dec 27 '21 at 16:43

1 Answers1

1

There isn't any difference once the code is loaded. The browser will load all pages on cache and it will loaded as faster as marge file.

There will be a difference to load first page but it is not remarkable.