I have raised a similar question, which mentioned the problem of merging compression scripts by business. Some of the answers in it are worth thinking about, and I would like to share them with you
Front-end modular project based on requirejs, what tools can you choose to achieve automated compression and merging
Regarding this issue, I have had similar questions before. Later, after consulting some information and asking some seniors for advice, I probably came up with some ideas of my own.
First of all, requirejs implements the amd specification. When you use requirejs for development, because of the need for modularization, a lot of js files will be generated, especially when used together with backbonejs.
In the process of network resource request, loading a slightly larger file is far more resource-saving than loading many small files.
So based on this factor, there is nothing wrong with using requirejs to type the script files of the entire site into one file.
As for your question, if all script files are directly typed into one main.js, it means that script files that may not be needed by my current page will also be loaded on the current page. I personally think this may be a matter of the number of files and the size of the files. It depends on the specific requirements of the project.
In addition, if we are in a SPA (or non-SPA), we can artificially classify the pages according to the functional templates, and then type the script files of all pages under each category into one file, so that different functional pages can be loaded differently according to the entrance. The packaged files should be able to somewhat avoid the previous problem.
I have raised a similar question, which mentioned the problem of merging compression scripts by business. Some of the answers in it are worth thinking about, and I would like to share them with you
Front-end modular project based on requirejs, what tools can you choose to achieve automated compression and merging
Regarding this issue, I have had similar questions before. Later, after consulting some information and asking some seniors for advice, I probably came up with some ideas of my own.
First of all, requirejs implements the amd specification. When you use requirejs for development, because of the need for modularization, a lot of js files will be generated, especially when used together with backbonejs.
In the process of network resource request, loading a slightly larger file is far more resource-saving than loading many small files.
So based on this factor, there is nothing wrong with using requirejs to type the script files of the entire site into one file.
As for your question, if all script files are directly typed into one main.js, it means that script files that may not be needed by my current page will also be loaded on the current page. I personally think this may be a matter of the number of files and the size of the files. It depends on the specific requirements of the project.
In addition, if we are in a SPA (or non-SPA), we can artificially classify the pages according to the functional templates, and then type the script files of all pages under each category into one file, so that different functional pages can be loaded differently according to the entrance. The packaged files should be able to somewhat avoid the previous problem.
Cache is not used when there are multiple pages