Is it better to minify javascript into a single bundle for the whole site, or a specific-to-each-page bundle?

后端 未结 4 1541
萌比男神i
萌比男神i 2021-01-03 22:18

When minifying JavaScripts together in web-development, is it better from the user-loading-time point of view to:

  1. make one single big bundle of JavaScript cont
4条回答
  •  再見小時候
    2021-01-03 23:11

    It really depends on the sizes and functions of the script. It's common to have a single master.js for all your pages, which contains all the functionality required by every page of your site, whilst having other js files for functionality that might only be needed on certain pages.

    Take Stack Overflow, for instance. They have a master.js file included on every page of the site, but when you visit a question page or the "ask a question" page you'll notice wmd.js. This script includes all the functionality for the editor which is needed on fewer pages.

提交回复
热议问题