3

This question indicates that there is a performance gain to having fewer js files because each one incurs an HTTP request. My question is regarding a local-file app (PhoneGap apps to be specific) in which the html and js files are all stored locally on the device, and so they are loaded via file://. Because they don't require an http request, is there still a performance benefit to having fewer files?

Community
  • 1
  • 1
xdumaine
  • 10,096
  • 6
  • 62
  • 103

3 Answers3

1

No, there shouldn't be a problem there. The primary problem with HTTP requests is latency. With local requests (especially to an SSD, as on phones and most tablets), latency is very low indeed.

I would double-check that having lots of individual, small files rather than one large file didn't make your app seem larger than it needs to be. It'll depend on the nature of the file system the files are stored in, but remember that most file systems have what we used to call a "cluster" size, which is the minimum amount of space a file ends up occupying (even if the file itself is actually much smaller than that). So if you have 100 1k files on a file system that has a minimum allocation unit of 4k, you'll occupy 400k; if you have one 100k file, you'll occupy 100k. Of course, even 400k isn't much on today's devices. :-)

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

I load about 200 .js files in my PhoneGap app with no noticeable performance problems, so I don't think so. Particularly, I use Require.js to load them as needed. For example, a button click handler might require the code needed to display the result of an action.

Best of luck!

robert
  • 5,093
  • 2
  • 20
  • 21
0

Try having 1000 different js files at 1kb, then load the program 100 times. Now have 1 js file at 1000kb and load it 100 times. Compare. :)

daniel
  • 1,435
  • 9
  • 16