1

i am wondering if i have to include all my javascript files to one entire file which file included to a folder? I just have for example 10 seperate js files into one javascript folder is bad for the website? Or it is ok?

P.S.I am new one to web development.

Photo of my Folder:

enter image description here

j08691
  • 204,283
  • 31
  • 260
  • 272
Crowman
  • 65
  • 5
  • it's bad because the browser will need to download each of those files individually, but you don't need to merge those files manually, there are tools that do this job for you and they are named bundlers. There are plenty: webpack, babel, rollup, parcel – Christian Vincenzo Traina May 20 '22 at 20:59

2 Answers2

2

If you're on a halfway decent server - one that can respond to clients in your service area quickly - it's unlikely to matter.

The biggest issue with including many separate files is that, if your server uses HTTP/1.1, clients will usually only be able to request a small handful of resources at a time (10 or less). If you have a whole bunch of resources that the client needs to download for the app to function, and the ping between the client and your server isn't great, this could increase the time it takes for your site to initially appear functional. But for only 10 script files, it's probably not an issue. (Look at many of the large sites of today, and you'll see that quite a few of them load a huge number of resources.)

If your server uses HTTP/2, clients will be able to download all files requested at once, without a limit on the number (except for bandwidth), so in that situation, using many different files is less likely to create issues.

Still, for larger applications, it could be a good idea to bundle up your script into a single file for production. There are many options out there, and they have a bunch of benefits - they're often considered essential for a modern application.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
  • Thank you for your reply! Look my js files its small scripts (for example to display some products or for css thins) so i dont think that will be a problem but i appreciate for your help, i will follow your advice! – Crowman May 20 '22 at 21:17
0

Ideally it is all in one file. On your development computer you will probably have several js files, especially as you begin including various js packages or frameworks to your web application (website). On your development machine, you can manually use a tool like grunt to automate the creation of that single js file from several different js files, or you can automate the build process and other pre-deployment tasks using a CI/CD pipeline.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91