Should I split my javascript into multiple files?

前端 未结 5 1173
感情败类
感情败类 2020-12-30 19:20

I\'m used to working with Java in which (as we know) each object is defined in its own file (generally speaking). I like this. I think it makes code easier to work with and

5条回答
  •  轮回少年
    2020-12-30 19:36

    There are two concerns here: a) ease of development b) client-side performance while downloading JS assets

    As far as development is concerned, modularity is never a bad thing; there are also Javascript autoloading frameworks (like requireJS and AMD) you can use to help you manage your modules and their dependencies.

    However, to address the second point, it is better to combine all your Javascript into a single file and minify it so that the client doesn't spend too much time downloading all your resources. There are tools (requireJS) that let you do this as well (i.e., combine all your dependencies into a single file).

提交回复
热议问题