Hi
I am learning the way javascript files are downloaded to the client side, so please correct me if I am wrong.
- Each vertical has a file called Cobalt.${vertical}.Common.js file.
- This contains a list of all javascript files for the vertical.
- This file is read at runtime and the files are resolved when ever a vertical's page is loaded; downloaded for all pages that the vertical owns that is.
- So, no matter how many pages a vertical owns, all the javascript files defined under the vertical are downloaded for each page.
I know they are no real worry about number of files downloaded here. Never the less, my question is, why vertical based routing and not page based routing and hence saving on render time and resources ?
To be more precise
Common file currently takes an array of relative urls
var includes = [];
includes.push("/External/Laconic/laconic.js");
includes.push("/Platform/js/v1/Alerts/Cobalt.Alerts.Utils.js");
includes.push("/Platform/js/v1/Alerts/Cobalt.Alerts.Constants.js");
includes.push("/Platform/js/v1/Alerts/Cobalt.Alerts.ListItemRenderer.js");
The page based routing could replace the array with a map like this
{
"page url 1":[
"javascript file 1",
"javascript file 2"
],
"page url 2":[
"javascript file 3",
"javascript file 4"
]
}
Website code could then read the common file and get the array of javascript files that are needed for a particular url from each vertical. This would reduce the number of javascript files loaded for each page by a significant percentage.