-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code splitting for FT.com #169
Comments
One strategy discussed may be to create named bundles with hard-coded lists of dependencies to be included in each. This is based on the assumption that all user facing applications will at least require most of the code included. e.g.:
This is similar to the current approach taken by n-ui but this may not be granular enough to fully exploit the benefits of caching and maintaining a hard-coded list may not be sustainable. |
A second strategy discussed by the team was to only split out dependencies which match a list of patterns, for example |
Tracking which files are required by each entry point is a tricky problem. By default Webpack adopts a strategy of prepending each filename with the name of the bundle that requires it. For example if an app has two entry points;
This is straightforward to reassemble ("go get all bundles matching |
Could we split dependencies by how frequently they change... i.e.
I suppose the rate of change is fluid for most repos. But there might be a sweet spot for increasing the number of files in a bundle in correlation with a lower rate of change, and thus the need to serve a new bundle. |
It would be good to check out dynamic imports and the available polyfills. It might be far fetched for us but I'm reminded of this article about code splitting on the google search site https://medium.com/@cramforce/designing-very-large-javascript-applications-6e013a3291a3 |
@benbarnett I think this approach probably has the most effort to reward ratio that we've discussed so far as it's the simplest to implement and can make a big difference. I'm concerned that manual maintenance of this may become a burden if the bundles are split more than a few times though. @kavanagh From the article you linked to:
Some of us did that years ago https://www.maketea.co.uk/2013/11/05/introducing-groundwork-js.html (AMD solved all this didn't it?! 😉) We do aim to support dynamic |
I believe this is now complete so I am closing this issue. |
Remove polyfill.io from Karma config
This issue is a catch-all for our discussions around developing a code splitting strategy for delivering JavaScript to our users of FT.com.
The reason we wish to enable code-splitting is to increase the cache-ability of our client-side code. JavaScript kilobytes are the most expensive so leveraging caching more is a key component of Anvil's performance strategy and meeting our success metric of decreasing time to interactive.
By splitting our JavaScript code effectively this should improve caching by:
[email protected]
, then we should aim to reuse that package across all of them. A user journey across these apps will be faster with assets ready in a warm cache.Webpack offers very powerful code splitting tools which should have the flexibility for us to build an appropriate strategy on top of. We have a basic example of this code splitting feature already which demonstrates how to split all of the npm packages required by a bundle into separate files but this is not an appropriate strategy for FT.com because:
There are also some other things to consider:
One a limitation of Webpack's runtime (a small module used when leveraging code splitting which can track each dependency loaded in the browser) is that it cannot dynamically load scripts. Therefore to initialise an app we must first send all of the scripts required to the browser. This is not necessarily a bad thing as it enables the use of resource hints and downloading scripts in parallel but it could also mean sending too much, decreasing the effectiveness of lazy loading.
The limitations of the Webpack runtime can be avoided by using techniques such as dynamic
import()
but this technique can actually increase the time it takes for scripts to be executed as the pieces may need to be parsed and executed in series in order to build a complete dependency tree. It is also unclear how this may be retrofitted to existing code.Our apps build their own assets and are not aware of the asset graph of other apps. In order for applications to reuse any scripts they must generate files with the same name and contents.
So, please submit your ideas for a JavaScript code splitting strategy which:
The text was updated successfully, but these errors were encountered: