I'm currently working on a big site which has quite a bit of technical debt we need to work away. There is quite a bit of js and css being loaded in the site. Currently the files are aggregated and minified in layers. One layer is used on each page, while the other layers are only loaded on pages that actually use them.
For example:
page 1:
- default.css
- page1.css
- some-feature.css
- default.js
- page1.js
- some-feature.js
page 2:
- default.css
- page2.css
- default.js
- page2.js
page 3:
- default.css
- page3.css
- some-feature.css
- some-other-feature.css
- default.js
- page3.js
- some-feature.js
- some-other-feature.js
Now, besides these resources there are a lot of external resources loaded as well, used for tracking, advertising, social integration etc.
I have the feeling that these resources would be served faster (both on initial and subsequent requests) if they were aggregated and minified in one single js and one single css file per page. For example page1.css + page1.js
and on another page it would be page2.css + page2.js
. Although this would result in less requests, it would also end up in loading some general content twice (like the original default.css
)
What would be the preferred way of loading these resources? And do you have any test results on this?